【发布时间】:2019-05-11 21:20:52
【问题描述】:
我正在尝试使用 PuTTY 通过 SSH 启动一个包含 selenium webdriver 用法的 python 脚本。在 SSH 终端中运行命令“sudo python3.4 [filepath].py”时,会引发“连接被拒绝”错误,但在服务器终端上运行相同的命令时,它会正常工作。
服务器是运行 Raspbian 的 Raspberry pi,并使用 geckodriver 作为 webdriver。使用 SSH 连接的计算机正在运行 Windows 10。
我尝试在运行 python 脚本之前输入“export DISPLAY=:0”。我还尝试通过 gnome-terminal 运行命令,希望它会强制 pi 加载 gui,因为我认为 selenium 驱动程序是图形驱动程序可能是问题的一部分。
我对 SSH:ing 非常陌生,对 selenium 还是很陌生。
为了使它比我的实际程序更简单,这只是一个启动 selenium 的脚本,它仍然显示相同的问题。
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'/home/pi/Downloads/gecko3/geckodriver')
driver.get('www.google.com')
driver.quit()
输出(进入我的 SSH 客户端)如下:
Traceback (most recent call last):
File "/home/pi/Desktop/webtest.py", line 3, in <module>
driver = webdriver.Firefox(executable_path=r'/home/pi/Downloads/gecko3/geckodriver')
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused
任何帮助将不胜感激
【问题讨论】:
-
请检查这个可能的解决方案selenium.common.exceptions.WebDriverException: Message: connection refused 是否解决了您的问题?
-
在 ARM 上避免 Selenium/Python/Firefox 组合,切换到 Chrome。 Firefox 和 Geckodriver 大多是错误的。如果您需要从源代码构建 Geckodriver,那么您就是 SOL,因为 Rust/Cargo 在 ARM 上存在构建错误。 (根据经验。我花了几个星期试图让 Selenium/Python/Firefox 在 ARM 上按预期工作。我最终放弃并切换到 Chrome)。
标签: python linux selenium selenium-webdriver ssh