我有一个Raspberry Pi,我想在重新启动crontab
时启动几个python脚本。我已经通过从终端调用python name_of_script.py
手动成功运行每个脚本,但是当我通过crontab运行时,我会看到以下回溯。
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
任何关于诊断的指针都会非常感激,不幸的是我的Google-fu让我失望了。
答案 0 :(得分:0)
对于Redhat / CentOS / Fedora,安装 Xvfb 和 pyvirtualdisplay
sudo yum install Xvfb
pip install pyvirtualdisplay
测试 Xvfb 和 pyvirtualdisplay ,不会出现异常
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1024,768))
display.start()
display.stop()
附上您的Selenium代码
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1024,768))
display.start()
driver = webdriver.Firefox()
driver.get(url)
driver.quit()
display.stop()