urllib3.exceptions.ProtocolError: ("连接中止",错误(10054,"远程主机强制关闭现有连接"))



我正在尝试使用Python Selenium chromedriver在chrome上打开一个网站。Chrome 浏览器正在打开(显示警告(,但网址未打开。

版本详细信息 : 铬 : 68.0.3440.106 硒 : 3.14.0 铬驱动程序 : 2.20 蟒蛇 : 2.7

我正在使用以下代码:

import time
from selenium import webdriver
import selenium
driver = webdriver.Chrome("C:/Python27/chromedriver.exe")
driver.get("https://vancouver.craigslist.ca/")
print(driver.title)
time.sleep(8)
driver.quit()

我得到以下错误:

C:Userssohil7777PycharmProjectstemp.pyvenvScriptspython.exe C:/Users/sohil7777/.PyCharmCE2018.2/config/scratches/scratch.py
Traceback (most recent call last):
File "C:/Users/sohil7777/.PyCharmCE2018.2/config/scratches/scratch.py", line 6, in <module>
driver = webdriver.Chrome("C:/Python27/chromedriver.exe")
File "C:Python27libsite-packagesseleniumwebdriverchromewebdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "C:Python27libsite-packagesseleniumwebdriverremotewebdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "C:Python27libsite-packagesseleniumwebdriverremotewebdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:Python27libsite-packagesseleniumwebdriverremotewebdriver.py", line 318, in execute
response = self.command_executor.execute(driver_command, params)
File "C:Python27libsite-packagesseleniumwebdriverremoteremote_connection.py", line 375, in execute
return self._request(command_info[0], url, body=data)
File "C:Python27libsite-packagesseleniumwebdriverremoteremote_connection.py", line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "C:Python27libsite-packagesurllib3request.py", line 72, in request
**urlopen_kw)
File "C:Python27libsite-packagesurllib3request.py", line 150, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "C:Python27libsite-packagesurllib3poolmanager.py", line 322, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "C:Python27libsite-packagesurllib3connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:Python27libsite-packagesurllib3utilretry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:Python27libsite-packagesurllib3connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:Python27libsite-packagesurllib3connectionpool.py", line 377, in _make_request
httplib_response = conn.getresponse(buffering=True)
File "C:Python27Libhttplib.py", line 1121, in getresponse
response.begin()
File "C:Python27Libhttplib.py", line 438, in begin
version, status, reason = self._read_status()
File "C:Python27Libhttplib.py", line 394, in _read_status
line = self.fp.readline(_MAXLINE + 1)
File "C:Python27Libsocket.py", line 480, in readline
data = self._sock.recv(self._rbufsize)
urllib3.exceptions.ProtocolError: ('Connection aborted.', error(10054, 'An existing connection was forcibly closed by the remote host'))

我错过了什么吗?非常感谢您的帮助

此错误消息...

urllib3.exceptions.ProtocolError: ('Connection aborted.', error(10054, 'An existing connection was forcibly closed by the remote host'))

。暗示ChromeDriver无法启动/生成新的WebBrowser,即Chrome浏览器会话。

您的主要问题是您使用的二进制文件版本之间的不兼容,如下所示:

  • 您正在使用的 chromedriver = 2.20
  • chromedriver=2.20的发行说明明确提到了以下内容:

支持Chrome v43-48

  • 您正在使用的 chrome=68.0
  • ChromeDriver v2.41的发行说明明确提到了以下内容:

支持铬 v67-69

因此,ChromeDriver v2.33Chrome浏览器v65.0之间存在明显的不匹配

溶液

  • ChromeDriver升级到当前的ChromeDriver v2.41级别。
  • Chrome 版本保持在Chrome v67-69级别之间。(根据ChromeDriver v2.41发行说明(
  • 通过IDE清理项目工作中心,并仅使用所需的依赖项重新生成项目。
  • 如果基本 Web 客户端版本太旧,请将其卸载并安装最新的 GA 和已发布版本的Web 客户端
  • 执行您的@Test

相关内容

  • 没有找到相关文章

最新更新