I was facing the same problem , you just need to follow these steps to resolve this issue :
Step 1. Run these command to install xvfb and pyvirtualdisplay.
$ sudo apt-get install xvfb python-pip
$ sudo pip install pyvirtualdisplay
For centOs :
$ yum install xvfb python-pip
$ pip install pyvirtualdisplay
What are doing here : we are providing display PyVirtualDisplay so that firefox driver can get a environment to run.
Step 2. Now you have to define display in you code like this :
display = Display(visible=0, size=(800, 600))
display.start()
And at the end of the code you have to close the display like:
display.stop()
So let's have a example of a selenium script including these display command :
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox()
browser.get('http://edu.yoursfriends.com')
print browser.title
browser.quit()
display.stop()
After following these 2 steps this problem was resolved for me , I hope it will help you, Enjoy!