Python Selenium ConnectionResetError:[WinError 10054]现有连接被远程主机强行关闭

8 python selenium python-3.x selenium-chromedriver

我正在使用python 3.6并使用最新版本的chromedriver,我曾尝试使用旧版的chromedriver,但我遇到了同样的问题,重启了我的电脑,出现了同样的问题。这是我运行来重现该错误的代码:

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("https://google.com")
Run Code Online (Sandbox Code Playgroud)

完全错误:

    driver.get("https://google.com")
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 268, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 254, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 464, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 488, in _request
    resp = self._conn.getresponse()
  File "C:\Python36\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "C:\Python36\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "C:\Python36\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Python36\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
Run Code Online (Sandbox Code Playgroud)

Set*_*eth 4

在 driver.get(" https://google.com ")之前添加 time.sleep(3) ,这将修复您的错误。然后,如果你像我一样,你会得到一个不同的错误。