2016-12-28 86 views
1

我有一個Raspberry Pi,我想用crontab重啓時啓動幾個python腳本。我通過從終端調用python name_of_script.py手動成功運行了每個腳本,但是當我通過crontab運行時,出現了以下回溯。使用Crontab @reboot for python腳本時出現Selenium錯誤

Traceback (most recent call last): 
    File "/home/pi/Desktop/photo_frames/becky/get_urls.py", line 11, in <module> 
    driver = webdriver.Firefox() 
    File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/webdriver.py", line 150, in __init__ 
    keep_alive=True) 
    File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__ 
    self.start_session(desired_capabilities, browser_profile) 
    File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session response = self.execute(Command.NEW_SESSION, capabilities) 
    File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute 
    self.error_handler.check_response(response) 
    File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: connection refused 

診斷的任何指針將不勝感激,不幸的是我的谷歌福已讓我失望這個錯誤。

回答

0

對於紅帽/ CentOS的/ Fedora的,安裝的Xvfbpyvirtualdisplay

sudo yum install Xvfb 
pip install pyvirtualdisplay 

測試的Xvfbpyvirtualdisplay,讓沒有例外

from pyvirtualdisplay import Display 
display = Display(visible=0, size=(1024,768)) 
display.start() 
display.stop() 

附上您的硒代碼

from pyvirtualdisplay import Display 
display = Display(visible=0, size=(1024,768)) 
display.start() 

driver = webdriver.Firefox() 
driver.get(url) 
driver.quit() 

display.stop()