Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium with Firefox webdriver results in error: Service geckodriver unexpectedly exited. Status code was: -11

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?

like image 245
StephenB Avatar asked Jan 02 '19 23:01

StephenB


1 Answers

This is at least a partial answer to your question.

  • Status code -11 means that subprocess experiences a segmentation fault. Read more about it at Determining if a python subprocess segmentation faults

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
like image 73
finefoot Avatar answered Oct 07 '22 22:10

finefoot