Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python selenium WebDriverException:无头Pi上出现“连接被拒绝”_Python_Selenium_Raspberry Pi_Headless_Iceweasel - Fatal编程技术网

Python selenium WebDriverException:无头Pi上出现“连接被拒绝”

Python selenium WebDriverException:无头Pi上出现“连接被拒绝”,python,selenium,raspberry-pi,headless,iceweasel,Python,Selenium,Raspberry Pi,Headless,Iceweasel,编辑:这似乎不是重复的,因为链接帖子的答案中没有任何建议可以修复错误。以下是运行脚本后的geckodriver.log: 1538960169585 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "--headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.xicOi27i6laa" 1538

编辑:这似乎不是重复的,因为链接帖子的答案中没有任何建议可以修复错误。以下是运行脚本后的geckodriver.log:

1538960169585   mozrunner::runner       INFO    Running command: "/usr/bin/firefox" "-marionette" "--headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.xicOi27i6laa"
1538960178656   Marionette      INFO    Listening on port 2828
^G[Child 17792] ###!!! ABORT: Aborting on channel error.: file /build/firefox-esr-YKrXxr/firefox-esr-52.9.0esr/ipc/glue/MessageChannel.cpp, line 2152
[Child 17792] ###!!! ABORT: Aborting on channel error.: file /build/firefox-esr-YKrXxr/firefox-esr-52.9.0esr/ipc/glue/MessageChannel.cpp, line 2152
我无法在无头Raspberry Pi 3 B+上创建运行python 3.5的webdriver实例。我跑了

sudo-apt-get安装python-pip-iceweasel-xvfb pip安装pyvirtualdisplay selenium

安装依赖项。但是,当我运行一个基本脚本来创建SeleniumWebDriver时,我会得到一条WebDriverException:Message:connection-Rejected消息

我的代码:

from selenium import webdriver
from pyvirtualdisplay import Display

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

profile = webdriver.FirefoxProfile()
profile.native_events_enabled = False

driver = webdriver.Firefox(profile)
错误消息:

 Traceback (most recent call last):
  File "simpletest", line 10, in <module>
    driver = webdriver.Firefox(firefox_profile=profile)
  File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

来自另一个论坛的消息表明上述代码应该可以工作。感谢您的帮助

我的新Raspbery Pi 3 B+也遇到了同样的问题。我通过安装geckodriver的旧版本修复了这个错误。我正在运行Raspbian GNU/Linux 9 stretch。如果您在Raspberry Pi上的bash终端上运行cat/etc/os版本,您可以查找自己的操作系统版本。您将得到如下输出:

PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
如果您使用的是Raspbian,那么当您安装Firefox时,您可能会收到版本52.9.0或更早。您可以通过在Raspberry Pi上的bash终端上运行firefox esr-version来检查这一点。请注意,iceweasel实际上是firefox esr。有关更多详细信息,请参阅。版本52.9.0是Raspbian最新的、完全受支持的版本,即使您运行sudo apt get update或sudo apt get upgrade firefox esr,版本也不会更改。事实上,sudo apt get upgrade firefox esr会告诉您firefox esr已经是最新版本52.9.0esr-1~deb9u1

由于无法升级Firefox,因此需要安装旧版本的geckodriver。在页面上,它推荐Firefox 55.0及更高版本,geckodriver v0.19.0推荐Selenium 3.5及更高版本。因此,您应该下载并安装geckodriver v0.18.0。下面的命令应该可以做到这一点:

curl -O https://github.com/mozilla/geckodriver/releases/download/v0.18.0/geckodriver-v0.18.0-arm7hf.tar.gz
tar -xzvf geckodriver-v0.18.0-arm7hf.tar.gz
sudo cp geckodriver /usr/local/bin/

注意:如果收到权限错误,您可能需要运行sudo chmod+x/usr/local/bin/geckodriver。

尝试添加“-headless”选项示例:options=options.add\u参数-headless@Infern0不幸的是,这并没有改变错误。