2

i have this python script:

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')  

driver = webdriver.Chrome("/usr/bin/chromedriver", chrome_options=options)

driver.set_window_size(300, 500)

wait = WebDriverWait(driver, 30)

if i run it on my pc it will work just fine

the problem is when i use it on a vps, SOMETIMES it throws me this bunch of erros:

    Traceback (most recent call last):
  File "acad.py", line 31, in <module>
    driver = webdriver.Chrome("/usr/bin/chromedriver", chrome_options=options)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 310, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/remote_connection.py", line 466, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/remote_connection.py", line 490, in _request
    resp = self._conn.getresponse()
  File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/usr/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.6/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

i have chromedriver on /usr/bin and chrome is under /usr/bin/google-chrome-stable

any ideas????

jfs
  • 399,953
  • 195
  • 994
  • 1,670
  • I had the same problem ... switched to gecko driver and all better. – SteveJ Feb 18 '18 at 04:21
  • Can you post your script??? – Soy TuPadre Feb 18 '18 at 05:20
  • 1
    related: [Regression in 3.8.1: Non-deterministic ConnectionResetError with chrome and chromedriver](https://github.com/SeleniumHQ/selenium/issues/5296). Check [whether there is enough memory (`free -m`)](https://stackoverflow.com/a/32413403/4279) – jfs Feb 18 '18 at 08:55
  • 2
    as a workaround, try `pip install selenium==3.8.0` (downgrade selenium version). – jfs Feb 18 '18 at 08:59

1 Answers1

0

A couple of things you might try.

I, personally, found that Firefox' geckogriver worked more reliable for me. I found others on the web reporting the same thing. Below is the script that I use for the geckodriver.

Also, as others have mentioned in the comments, memory management is critical with either driver. If your code throws an exception, the OS will not automatically destroy the resource (it treats is as an opened web browser). You have to be extremely careful to always exit with a driver.quit() statement. A great pattern is to use python's 'with' statement. The combination of the above made the problem go away for me.

[My connection script]

headless = True

options = webdriver.FirefoxOptions()
if "Linux" in platform.system():
    path = "path/to/geckodriver"
else:
    path = "path/to/geckodriver.exe")

if headless:
    options.add_argument("-headless")
driver = webdriver.Firefox(executable_path=path, firefox_options=options)
driver.implicitly_wait(10)
SteveJ
  • 3,034
  • 2
  • 27
  • 47