I have a python script which will only be triggered by calling my.ip.address/test. It works fine if I run the PHP code via command line.

However,if I access the test automation via browser using the url specified, it gives me this error:

Traceback (most recent call last): File "scripts/crawler.py",
line 10, in driver = webdriver.Firefox(capabilities={"marionette":True}) File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py",
line 152, in __init__ keep_alive=True) File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 98, in __init__ self.start_session(desired_capabilities, browser_profile) File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 188, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 252, in execute self.error_handler.check_response(response) File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py",    
line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: connection refused

Error in geckodriver.log:

1495299180874   geckodriver::marionette INFO    Starting browser /usr/lib/firefox/firefox with args ["-marionette"]
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :99

Simple Python code:

#!/usr/bin/env python2

from pyvirtualdisplay import Display
from selenium import webdriver   
import time
import sys

driver = webdriver.Firefox(capabilities={"marionette":True})

display = Display(visible=0, size=(800,600))

print driver.title

PHP code snippet for /test endpoint:

$cmd = 'xvfb-run -a python scripts/crawler.py'
return shell_exec($cmd);

Already installed Xvfb and run it:

$ whoami
  codekaizer #with root privileges
$ Xvfb :99 -screen 0 1024x768x24 -ac -fbdir /tmp/.X11-unix/X99 &

I've verified that /tmp/.X11-unix/X99 socket is listening to the Xvfb process.

I'm quite stuck right now and really appreciate someone's help!


  • Firefox 53.0
  • Geckodriver 0.16.1
  • Fedora 22 x86_64

Thanks! - ck

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.