8

Setup:

  • selenium: 3.141.0
  • python: 3.6.7
  • heroku-stack: heroku-18
  • headless-chrome: v71.0.3578.80 buildpack installed
  • chromedriver: v2.44.609551 buildpack installed

I'm getting this error when using selenium in heroku:

urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

I googled but didn't have luck. The error happens at the last line of this code.


Code

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

UA = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36' \
     '(KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
DRIVER_PATH = '/app/.chromedriver/bin/chromedriver'

chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = '/app/.apt/usr/bin/google-chrome'
chrome_options.add_argument(f'--user-agent={UA}')
chrome_options.add_argument(f'--proxy-server=http://my_private_proxy.com:my_port')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')

chrome = webdriver.Chrome(executable_path=DRIVER_PATH, options=options)
madtyn
  • 1,469
  • 27
  • 55

1 Answers1

3

This error message...

urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

...implies that the ChromeDriver in Headless mode was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.

Some information regarding the versions of the binaries you are using would have helped us to analyze the error in a better way. However, this issue of urllib3 can be obseved due to several reasons as mentioned below:

This flag is no longer necessary on Linux or macOS. It will become unnecessary on Windows as soon as SwiftShader fails an assert on Windows in headless mode gets fixed.

Solution

  • Upgrade ChromeDriver to current ChromeDriver v2.44 level.
  • Keep Chrome version between Chrome v69-71 levels. (as per ChromeDriver v2.44 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.
  • Take a System Reboot.
  • Execute your @Test.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Heroku is a cloud platform as a service I'm using as server. I updated the version for chromedriver in the post. I don't know how to get the headless version from the server, but being provided by Heroku, must be pretty modern. I can't do IDE things in Heroku, but I'm doing the changes you told me in the source code, review the binary and driver paths and reboot the Heroku server. Don't know how to deal with the @Test thing either. Meanwhile I'm trying, thanks. :-) – madtyn Dec 11 '18 at 11:30
  • 1
    Seems like some of your advice did work. Now I got to a different SessionNotCreatedException: "Session not created from crash tab". I'm working through this now. Thanks. – madtyn Dec 11 '18 at 12:21
  • 1
    @madtyn For the error **SessionNotCreatedException: "Session not created from crash tab"** check the **Update** section within my Answer in the discussion [org.openqa.selenium.SessionNotCreatedException: session not created exception from tab crashed error when executing from Jenkins CI server](https://stackoverflow.com/questions/49518157/org-openqa-selenium-sessionnotcreatedexception-session-not-created-exception-fr/49518339#49518339) – undetected Selenium Dec 12 '18 at 09:12