5

I have been wracking my brain over this. I'm getting the error:

System geckodriver unexpectedly exited. Status code: -11.

I am using a Linux server that is a shared hosting web server. I have everything set up in a virtual environment.

  • Linux Server - CentOS, Release: 7.4.1708
  • Selenium version 3.141.0
  • geckodriver version 0.23.0
  • Firefox 60.3.0
  • Python 3.6.2 and cannot use a newer version

Python, Selenium and Geckodriver reside on a virtual environment on a Linux web server. Firefox resides outside of the virtual environment

export PATH=$PATH:/path/to/geckodriver

to my terminal to have geckodriver be used in the PATH environment variable.

Below is my code:

#!/home/DIRECTORY/DIRECTORY/DIRECTORY/venv/bin/python

# -*- coding: UTF-8 -*-
import cgitb
import cgi
from selenium import webdriver
from selenium.webdriver import FirefoxOptions

cgitb.enable()
print ("Content-Type: text/html; charset=utf-8\n\n")
path = r'/home/DIRECTORY/DIRECTORY/DIRECTORY/venv/bin/geckodriver'
binary = FirefoxBinary(r'/usr/lib64/firefox')

opts = FirefoxOptions()
opts.add_argument("--headless")

browser = webdriver.Firefox(firefox_options=opts, firefox_binary=binary, executable_path=path)
rowser.get("http://google.com/")
print ("Headless Firefox Initialized")
browser.quit()

Here is my traceback error:

Traceback (most recent call last):
File "selen.py", line 20, in <module>
browser = webdriver.Firefox(firefox_options=opts, executable_path=path)
File "/home/DIRECTORY/DIRECTORY/DIRECTORY/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/home/DIRECTORY/DIRECTORY/DIRECTORY/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/DIRECTORY/DIRECTORY/DIRECTORY/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /home/DIRECTORY/DIRECTORY/DIRECTORY/venv/bin/geckodriver unexpectedly exited. Status code was: -11

Why am I getting this error and how do I fix it?

StephenB
  • 166
  • 2
  • 14
  • -11 means a segmentation fault in the child process, if that helps. – Davis Herring Jan 03 '19 at 02:17
  • 2
    @Jayjayyy: It appears in the [`subprocess` documentation](https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module). (True [exit status values](http://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html) are non-negative, so you know they’re special somehow.) – Davis Herring Jan 03 '19 at 02:49
  • @Jayjayyy: `subprocess` **represents** the termination of a child because of a signal (rather than an `exit`, which is the only other choice) with a negative number that indicates the signal (and can’t be confused with an exit code). (Segmentation faults happen during execution, not before it, although one could theoretically happen after `fork` and before `exec`.) – Davis Herring Jan 03 '19 at 05:02
  • Thanks guys! How do I fix the segmentation fault for geckodriver.exe? I tried running 'geckodriver --version' through a terminal for the server yesterday, and it came back with the same error: segmentation fault. The permissions for the driver is set to 755. – StephenB Jan 03 '19 at 16:15
  • Please run `file /home/DIRECTORY/DIRECTORY/DIRECTORY/venv/bin/geckodriver` and post the output. – SiKing Jan 04 '19 at 17:28
  • @SiKing, I am getting this output: `ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, stripped` – StephenB Jan 04 '19 at 19:58
  • From your comment above, it sounded as if you might be trying to run a Windows binary on a Linux OS. But that is not the case. – SiKing Jan 04 '19 at 20:54

1 Answers1

6

This is at least a partial answer to your question.


In the past, there were some problems with certain versions of Selenium not working well together with certain versions of Firefox and/or geckodriver. Find out your versions, update them to the most recent versions if possible and look for existing bug reports for your versions.

The following versions work well together on my Ubuntu 18.04 LTS Bionic Beaver system:

  • Check Python version

    $ python3 --version
    Python 3.6.7
    
  • Check Selenium version

    $ python3 -c "import selenium; print(selenium.__version__)"
    3.141.0
    
  • Check Firefox version

    $ firefox --version
    Mozilla Firefox 64.0
    
  • Check geckodriver version

    $ geckodriver --version
    geckodriver 0.23.0 ( 2018-10-04)
    
    The source code of this program is available from
    testing/geckodriver in https://hg.mozilla.org/mozilla-central.
    
    This program is subject to the terms of the Mozilla Public License 2.0.
    You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.
    

If you have to browse to a special path to make those commands work and those commands don't work directly in your terminal or virtual environment, you might need to set one of the following keyword arguments in your call to webdriver.Firefox:

  • firefox_binary – Instance of FirefoxBinary or full path to the Firefox binary. If undefined, the system default Firefox installation will be used.
  • executable_path – Full path to override which geckodriver binary to use for Firefox 47.0.1 and greater, which defaults to picking up the binary from the system path.

Run nothing fancy as a test, but a minimal example of Selenium with Firefox in headless mode only, for example minimal_selenium_test.py:

import selenium.webdriver

options = selenium.webdriver.FirefoxOptions()
options.add_argument("--headless")

driver = selenium.webdriver.Firefox(firefox_options=options)
driver.get('https://www.python.org/')
print(driver.title)
driver.close()

This should work on your local laptop as well as on a virtual server as well as inside a Docker container and should print:

$ python3 minimal_selenium_test.py 
Welcome to Python.org
finefoot
  • 9,914
  • 7
  • 59
  • 102