WebDriverException: Message: connection refused

Viewed 2903

I am using selenium with geckodriver try to get a html page. Below is the code that I am using

from pyvirtualdisplay import Display    
from selenium import webdriver  

#start the virtual display      
display = Display(visible=0, size=(800, 600))   
display.start()

# start the browser. Using firefox.
browser = webdriver.Firefox()

browser.get('https://www.google.com')

print browser.title

browser.quit()

display.stop()

When I execute it with python, I get the following error message.

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
    keep_alive=True)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

I consulted geckodriver.log.

1500842848329   geckodriver INFO    geckodriver 0.18.0
1500842848362   geckodriver INFO    Listening on 127.0.0.1:45467
1500842849526   geckodriver::marionette INFO    Starting browser /usr/bin/firefox with args ["-marionette"]

I am unsure where to look next. Any hints?

Update1: It seems that when I did a power reset on the VPS, the script started to work. I investigated it further and remembered that there were four defunct process running from previous firefox executions which I had to kill. I don't know enough about the internals of the process handling in Linux to fully understand this. Is geckodriver getting confuse?

1 Answers

I had this issue as well...even on a machine with X server running and a fully functional KDE environment. Turns out there are strict version requirements when using geckodriver and Firefox. I was running an older version of Firefox with the latest version of geckodriver. Once I downloaded a version listed in the release notes (and specified the path to that firefox binary in my webdriver declaration), it worked fine:

driver = webdriver.Firefox(firefox_binary='/path/to/latest/firefox/binary')

https://github.com/mozilla/geckodriver/releases

Related