Search code examples
pythonseleniumchrome-web-driver

I'm trying to start the chrome webdriver on linux, but it hangs, then closes


I'm making a program with selenium (python). It was working, and out of nowhere, the webdriver no longer works. I'm developing on a windows environment (and it works fine), but once I upload the code to the production server (Ubuntu), I try to open the web driver and it only displays data;, the driver hangs, then closes. No code after that continues.

Example:

print("Starting web driver")
driver = webdriver.Chrome(driver_path, options=opt)
print("Opening URL") # This code doesn't run
driver.get(config.url) # This code doesn't run

Things I've tried:

  • Running it on Windows (it works properly)

  • Updating the webdriver

  • Running it outside of the venv

  • Running the driver in a new, isolated environment

  • Wrapping the entire code within try-except (no errors output)

  • Running with the argument --headless

Edit: I'm running python3.7, chrome webdriver V 75.0.3770.90

Edit2: the driver_path var is the relative path to the chromedriver file. The opt are my list of chrome options:

opt = Options()
opt.add_argument('--no-sandbox')
opt.add_argument('--disable-dev-shm-usage')
profile = {"plugins.always_open_pdf_externally": True,
           "download.default_directory": download_directory,
           "download.prompt_for_download": False,
           "download.directory_upgrade": True}
opt.add_experimental_option("prefs", profile)

I'm also using gunicorn as my webserver, but running it with the default (flask) webserver, I still encounter the issue. I'm also executing functions I've written for selenium through a flask-based web application (its a web app for work) The ubuntu machine that's running the script has a desktop environment installed.

What happens

After 15-25 seconds, the windows closes with no output in the terminal. After ~90 seconds, I get a message in the terminal saying:

Message: session not created
from disconnected: unable to connect to renderer
    (Session info: chrome=75.0.3770.90)

I've also noticed that the chrome driver takes more time to open than usual.

Edit3: I've literally deleted then entire virtual machine and reinstalled it from scratch, and I'm still running into the same issue, I've reverted to an older version and it still doesn't run, which makes no logical sense. My only thought is that there is some configuration error or that something is interfering with it.

Edit4: I was able to get the log from the webdriver by adding the argument --verbose Heres the log:

[1562179109.454][INFO]: resolved localhost to ["::1","127.0.0.1"]
[1562179111.454][WARNING]: Timed out connecting to Chrome, retrying...
[1562179111.454][INFO]: resolved localhost to ["::1","127.0.0.1"]
[1562179115.454][WARNING]: Timed out connecting to Chrome, retrying...
[1562179115.455][INFO]: resolved localhost to ["::1","127.0.0.1"]
[1562179123.454][WARNING]: Timed out connecting to Chrome, retrying...
[1562179123.455][INFO]: resolved localhost to ["::1","127.0.0.1"]
[1562179139.455][WARNING]: Timed out connecting to Chrome, giving up.
[1562179139.506][INFO]: [42e538ee02eb06b9ac776969dddf01d1] RESPONSE InitSession ERROR session not created
from disconnected: unable to connect to renderer
  (Session info: chrome=75.0.3770.90)
[1562179139.506][DEBUG]: Log type 'driver' lost 9 entries on destruction
[1562179139.506][DEBUG]: Log type 'browser' lost 0 entries on destruction

I'm not too familiar with Linux, but from what I've seen in the past, I have a feeling its something to do with /etc/hosts (idk?)

Edit5: I've noticed this started happening after I installed windscribe (vpn) which makes me think that windscribe is interfering with the connection somehow.


Solution

  • I turns out, windscribe (vpn) interferes with the connection to the chrome webdriver, I believe it has something to do with its built-in firewall, after uninstalling it, calling sudo apt autoremove -y and a reboot, it works properly!

    Edit: I re-installed the VPN (windscribe) and de-activated the included firewall and it worked properly after that.