user7114146
user7114146

Reputation:

Python selenium ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

I am using python 3.6 and using the latest version of chromedriver, I have tried using older version of chromedriver and I get the same problem restarted my pc, same problem. this is the code I run to reproduce the error:

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("https://google.com")

full error:

    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

Upvotes: 11

Views: 16042

Answers (4)

Thom Ives
Thom Ives

Reputation: 3989

Seth and Jack1990's answers above were helpful to me for troubleshooting the use of IEDriverServer from python. I did try Adhithiya's advice, but that did not help with my problem.

This GitHub site was VERY helpful to me. The section to pay attention to there is "Required Configuration". I had followed this first, however, in the statement, "On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone." I found that I had to do this for Windows 10 also. In fact, the python error messages were very clear on this point. They all need to be enabled or disabled. They do NOT have to be at the same level.

Also, I did have to play around with the value of x in time.sleep(x). This sleep command is the one between driver = webdriver.Ie() and driver.get("http://testwisely.com/demo") in the code below. If set to 5 for me, the ie driver fires off a local host first and complains that it can't be reached and then it connects to the page that I wanted it to (most of the time!).

The good news is that the other 3 web browsers work great! I found that running a driver.quit() command for Chrome, Firefox and Edge (in Windows 10) webdrivers successfully shuts down those browsers, whereas the iedriver version did not shutdown IE.

My code is below in case you'd like to use it for experimentation.

from selenium import webdriver
import time

browser_to_use = "Edge" # "Chrome" "Firefox" "Ie" 

if browser_to_use == "Chrome":
    driver = webdriver.Chrome()
elif browser_to_use == "Firefox":
    driver = webdriver.Firefox()
elif browser_to_use == "Ie":  # This sucks!
    driver = webdriver.Ie()
    time.sleep(5)
elif browser_to_use == "Edge":
    driver = webdriver.Edge()

driver.get("http://testwisely.com/demo")
time.sleep(5)
driver.quit()

Upvotes: 2

Jack1990
Jack1990

Reputation: 11

Downloading an old version (3.8) also fixes the issue, but the test will run extremely slowly...

You can find the link here: http://selenium-release.storage.googleapis.com/index.html?path=3.8/

Upvotes: 1

Adhithiya Raghu
Adhithiya Raghu

Reputation: 155

Chromedriver might be running in the background, check Background processes in your task manager.

If you find more than one instance of chromedriver running, kill all the process manually and try running the program again.

You should be good to go.

Upvotes: 2

Seth
Seth

Reputation: 716

Put in a time.sleep(3) before driver.get("https://google.com"), that will fix your error. Then if you're like me you'll get a different error.

Upvotes: 4

Related Questions