拒绝连接并轮询更改失败:尝试使用Selenium GeckoDriver和Firefox提取资源错误时出现NetworkError

时间:2019-06-04 14:50:51

标签: python selenium firefox geckodriver splinter

根据标题,现在,Firefox打开,似乎什么也不做,然后消失了!

  1. 我以前已经从本地ubuntu 16.04 VM运行了此程序,一切都很好。

(是的,我已经升级到最新的硒等,如下所示: 硒3.141.0 碎片0.10.0 六个1.12.0 urllib3 1.25.3) 现在,geckodriver.log显示以下内容:

1559646629845   geckodriver     INFO    Listening on 127.0.0.1:60172  
1559646630836   mozprofile::profile     INFO    Using profile path /tmp/rust_mozprofile.5DqFww40mZ6W  
1559646630851   geckodriver::marionette INFO    Starting browser /usr/bin/firefox  
1559646630857   geckodriver::marionette INFO    Connecting to Marionette on localhost:46681  
1559646631959   addons.webextension.screenshots@mozilla.org     WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons  
1559646631960   addons.webextension.screenshots@mozilla.org     WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/  
1559646631960   addons.webextension.screenshots@mozilla.org     WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*  
1559646637156   Marionette      INFO    Listening on port 2828  
console.error: BroadcastService:  
  receivedBroadcastMessage: handler for  
  remote-settings/monitor_changes  
  threw error:  
  Message: Error: Polling for changes failed: NetworkError when attempting to fetch resource..  
  Stack:  
    remoteSettingsFunction/remoteSettings.pollChanges@resource://services-settings/remote-settings.js:190:13  
JavaScript error: jar:file:///usr/lib/firefox/omni.ja!/components/nsUrlClassifierListManager.js, line 329: NS_ERROR_NOT_INITIALIZED: Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIUrlClassifierDBService.getTables]  
JavaScript error: jar:file:///usr/lib/firefox/omni.ja!/components/nsUrlClassifierListManager.js, line 329: NS_ERROR_NOT_INITIALIZED: Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIUrlClassifierDBService.getTables]  
1559646742440   Marionette      INFO    Stopped listening on port 2828ss  
  1. 我也在远程ubuntu-16.04 VM(不带GUI)上尝试了此操作,控制台显示了相同的“连接被拒绝”消息,但这次geckodriver.log显示了另一个问题,如下所示: (硒3.141.0 六个1.12.0 碎片0.10.0 urllib3 1.25.3)

    1559563047915   geckodriver     INFO    geckodriver 0.18.0  
    1559563047918   geckodriver     INFO    Listening on 127.0.0.1:51758  
    1559563049045   geckodriver::marionette INFO    Starting browser  /usr/bin/firefox with args ["-marionette"]  
    MobaXterm X11 proxy: Unsupported authorisation protocol  
    Failed to connect to Mir: Failed to connect to server socket: No such file or directory  
    Unable to init server: Broadway display type not supported:   localhost:11.0  
    Error: cannot open display: localhost:11.0  
    1559644244502   geckodriver     INFO    geckodriver 0.18.0
    1559644244506   geckodriver     INFO    Listening on 127.0.0.1:53086
    1559644245634   geckodriver::marionette INFO    Starting browser /usr/bin/firefox with args ["-marionette"]
    MobaXterm X11 proxy: Unsupported authorisation protocol
    Failed to connect to Mir: Failed to connect to server socket: No such file or directory
    Unable to init server: Broadway display type not supported: localhost:10.0
    Error: cannot open display: localhost:10.0
    

我的测试代码是:

from splinter import Browser
browser = Browser()
browser.visit( 'https://www.google.com' )
browser.fill( 'q', 'splinter - python acceptance testing     for web application' )
browser.quit()

我很高兴收到与硒“连接被拒绝”类型问题类似的问题……我希望找到特定于python的解决方案,在我看来这是“网络问题”或“显示问题”。 ..

1 个答案:

答案 0 :(得分:0)

此错误消息...

1559646629845   geckodriver     INFO    Listening on 127.0.0.1:60172  
1559646630836   mozprofile::profile     INFO    Using profile path /tmp/rust_mozprofile.5DqFww40mZ6W  
1559646630851   geckodriver::marionette INFO    Starting browser /usr/bin/firefox  
1559646630857   geckodriver::marionette INFO    Connecting to Marionette on localhost:46681  
1559646631959   addons.webextension.screenshots@mozilla.org     WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons  
1559646637156   Marionette      INFO    Listening on port 2828  
console.error: BroadcastService:  
  receivedBroadcastMessage: handler for  
  remote-settings/monitor_changes  
  threw error:  
  Message: Error: Polling for changes failed: NetworkError when attempting to fetch resource..  
  Stack:  
    remoteSettingsFunction/remoteSettings.pollChanges@resource://services-settings/remote-settings.js:190:13  
JavaScript error: jar:file:///usr/lib/firefox/omni.ja!/components/nsUrlClassifierListManager.js, line 329: NS_ERROR_NOT_INITIALIZED: Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIUrlClassifierDBService.getTables]  
1559646742440   Marionette      INFO    Stopped listening on port 2828s

...表示 GeckoDriver 无法启动/产生新的 WebBrowsing会话,即 Firefox浏览器会话。

您的主要问题是所使用的二进制版本之间的不兼容性

  • 您的 GeckoDriver 版本 geckodriver v0.18.0 。 (按照第二组日志 ... geckodriver INFO geckodriver 0.18.0 ... 中的第一行)
  • 您的 Selenium Client 版本是 3.141.0
  • 您不知道您的 Firefox 版本。

因此 GeckoDriver v0.18.0 Selenium Client v3.141.0 之间存在明显的不匹配。


解决方案

  • 升级到当前水平Version 3.141.59
  • GeckoDriver 升级到最新的GeckoDriver v0.24.0级别。
  • 确保 GeckoDriver 位于所需位置。
  • GeckoDriver 具有非root用户的可执行权限。
  • Firefox 升级到当前的 Firefox v65.0.2 级别。
  • 通过您的 IDE
  • 清理您的项目工作区重建您的项目,并且仅具有必需的依赖项。
  • 如果您的基本 Web客户端版本太旧,则将其卸载并安装最新版本的 Web客户端 GA。
  • 始终在driver.quit()方法内调用tearDown(){},以优雅地关闭和销毁 WebDriver Web Client 实例。
  

注意:请始终保持以下GeckoDriver, Selenium and Firefox Browser compatibility matrix

supported_platforms_geckodriver_24

  

您可以在Which Firefox browser versions supported for given Geckodriver version?

中找到相关的详细讨论

Outro