問題描述
我正在嘗試使用 Python Selenium chromedriver 在 chrome 上打開一個網站.Chrome 瀏覽器正在打開(帶有警告)并且 url 沒有打開.
I am trying to open a website on chrome using Python Selenium chromedriver. Chrome browser is opening (with warnings) and the url is not opening.
版本詳情:Chrome:68.0.3440.106硒:3.14.0鉻驅動程序:2.20蟒蛇:2.7
Version details : Chrome : 68.0.3440.106 selenium : 3.14.0 chromedriver : 2.20 python : 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:Userssohil7777PycharmProjects emp.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-packagesseleniumwebdriver
emotewebdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "C:Python27libsite-packagesseleniumwebdriver
emotewebdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:Python27libsite-packagesseleniumwebdriver
emotewebdriver.py", line 318, in execute
response = self.command_executor.execute(driver_command, params)
File "C:Python27libsite-packagesseleniumwebdriver
emote
emote_connection.py", line 375, in execute
return self._request(command_info[0], url, body=data)
File "C:Python27libsite-packagesseleniumwebdriver
emote
emote_connection.py", line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "C:Python27libsite-packagesurllib3
equest.py", line 72, in request
**urlopen_kw)
File "C:Python27libsite-packagesurllib3
equest.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-packagesurllib3util
etry.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'))
我錯過了什么嗎?非常感謝您的幫助
Am i missing something? Really appreciate your help
推薦答案
這個錯誤信息...
urllib3.exceptions.ProtocolError: ('Connection aborted.', error(10054, 'An existing connection was forcibly closed by the remote host'))
...暗示 ChromeDriver 無法啟動/生成新的 WebBrowser 即 Chrome 瀏覽器 會話.
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
您的主要問題是您使用的二進制文件版本之間的不兼容性,如下所示:
Your main issue is the incompatibility between the version of the binaries you are using as follows:
- 您正在使用 chromedriver=2.20
- chromedriver=2.20 的發行說明明確提及以下內容:
支持 Chrome v43-48
- 您正在使用 chrome=68.0
- ChromeDriver v2.41 明確提及以下內容:
- 將 ChromeDriver 升級到當前的 ChromeDriverv2.41 級別.
- 將 Chrome 版本保持在 Chrome v67-69 級別之間.(根據 ChromeDriver v2.41 發行說明)
- 清理你的項目工作區通過你的IDE和重建你的項目只需要依賴.
- 如果您的基本 Web 客戶端 版本太舊,請卸載它并安裝最新的 GA 和發布版本的 Web 客戶端.
- 執行你的
@Test
. - Upgrade ChromeDriver to current ChromeDriver v2.41 level.
- Keep Chrome version between Chrome v67-69 levels. (as per ChromeDriver v2.41 release notes)
- Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
- If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
- Execute your
@Test
.
支持 Chrome v67-69
所以 ChromeDriver v2.33 和 Chrome 瀏覽器 v65.0
這篇關于urllib3.exceptions.ProtocolError: ('Connection aborted.', error(10054, '現有連接被遠程主機強行關閉'))的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!