Geckodriver 0.18.0 随机无响应。由几个壁虎驱动器相互干扰引起的?
Geckodriver 0.18.0 random nonresponsiveness. Caused by several geckodrivers interfering with each other?
短版
我是 运行 Selenium 3.11.0 + Geckodriver 0.18.0 + Firefox 59.0.2 Ubuntu 14.04.5。尝试打开 URL 时,Selenium 有时会抛出以下错误
[Errno 111] Connection refused https://www.example.com
Geckodriver.log 显示
1523165125053 geckodriver INFO geckodriver 0.18.0
1523165125060 geckodriver INFO Listening on 127.0.0.1:37893
1523165126313 geckodriver::marionette INFO Starting browser /usr/bin/firefox with args ["-marionette"]
1523165127142 Marionette INFO Enabled via --marionette
(firefox:28158): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:28158): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(firefox:28158): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:28158): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(firefox:28158): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:28158): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
1523165129816 Marionette INFO Listening on port 41316
1523165129876 Marionette WARN TLS certificate errors will be ignored for this session
ATTENTION: default value of option force_s3tc_enable overridden by environment.
JavaScript error: jar:file:///usr/lib/firefox/omni.ja!/components/PeerConnection.js, line 1816: TypeError: this._dompc._pc is undefined
[Child 28235, Chrome_ChildThread] WARNING: pipe error (16): Connection reset by peer: file /build/firefox-4kFFck/firefox-59.0.2+build1/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
[Child 28235, Chrome_ChildThread] WARNING: pipe error (3): Connection reset by peer: file /build/firefox-4kFFck/firefox-59.0.2+build1/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
怎么回事?
长版:
我在 cron 中安排了一组夜间作业。它们从单独的 shell 脚本开始,看起来像这样
if pgrep "Xvfb" > /dev/null
then
echo "Xvfb already running"
else
Xvfb :99 -screen 0 1024x768x24 2>&1 >/dev/null &
fi
export DISPLAY=:99
python dostuff.py
有几个 shell 与上面的相似。他们每个人都启动一个 Python2.7 脚本(例如上面示例中的 dostuff.py),看起来像这样(唯一的区别是不同的 url 集)
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
for j in list_of_urls:
driver_get(j)
# do stuff to j
driver.quit()
这在大多数情况下都可以正常工作,但有时脚本会变得无响应,并且出现连接被拒绝的错误。这似乎总是发生在循环的中间。 IE。 urls[0] 打开正常,但 urls[1] 可能会失败。
在谷歌搜索从 geckodriver.log 中找到的错误消息时,我找到了这个 https://github.com/mozilla/geckodriver/issues/828。由于我没有最大化任何 windows,我不认为我的问题与票证中描述的相同(尽管错误消息显示相似)。
我是 运行 几个 firefox 实例(它们都使用相同的 DISPLAY=:99)。这会不会导致不同的 Firefox 实例相互干扰?
我还应该提到,当我使用 Firefox 44(不需要 Geckodriver)时,这个设置工作得很好。另一件可能很重要的事情是,据我所知,只有当我 运行 使用 Xvfb 的无头浏览器脚本时才会发生这种情况。
正如您从我的问题中看到的那样,我对 Xvfb、Geckodriver 和 Firefox 的了解略有不足。如果有人知道发生了什么,我将不胜感激。
更新:更新到 Geckodriver 0.20.1 解决了问题 - 有点。
问题仍然出现(大约每打开 100 页就会出现一次)。 driver.get(j)
偶尔会失败,但会引发超时错误,可以捕获并处理。
短版
我是 运行 Selenium 3.11.0 + Geckodriver 0.18.0 + Firefox 59.0.2 Ubuntu 14.04.5。尝试打开 URL 时,Selenium 有时会抛出以下错误
[Errno 111] Connection refused https://www.example.com
Geckodriver.log 显示
1523165125053 geckodriver INFO geckodriver 0.18.0
1523165125060 geckodriver INFO Listening on 127.0.0.1:37893
1523165126313 geckodriver::marionette INFO Starting browser /usr/bin/firefox with args ["-marionette"]
1523165127142 Marionette INFO Enabled via --marionette
(firefox:28158): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:28158): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(firefox:28158): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:28158): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(firefox:28158): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:28158): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
1523165129816 Marionette INFO Listening on port 41316
1523165129876 Marionette WARN TLS certificate errors will be ignored for this session
ATTENTION: default value of option force_s3tc_enable overridden by environment.
JavaScript error: jar:file:///usr/lib/firefox/omni.ja!/components/PeerConnection.js, line 1816: TypeError: this._dompc._pc is undefined
[Child 28235, Chrome_ChildThread] WARNING: pipe error (16): Connection reset by peer: file /build/firefox-4kFFck/firefox-59.0.2+build1/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
[Child 28235, Chrome_ChildThread] WARNING: pipe error (3): Connection reset by peer: file /build/firefox-4kFFck/firefox-59.0.2+build1/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
怎么回事?
长版:
我在 cron 中安排了一组夜间作业。它们从单独的 shell 脚本开始,看起来像这样
if pgrep "Xvfb" > /dev/null
then
echo "Xvfb already running"
else
Xvfb :99 -screen 0 1024x768x24 2>&1 >/dev/null &
fi
export DISPLAY=:99
python dostuff.py
有几个 shell 与上面的相似。他们每个人都启动一个 Python2.7 脚本(例如上面示例中的 dostuff.py),看起来像这样(唯一的区别是不同的 url 集)
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
for j in list_of_urls:
driver_get(j)
# do stuff to j
driver.quit()
这在大多数情况下都可以正常工作,但有时脚本会变得无响应,并且出现连接被拒绝的错误。这似乎总是发生在循环的中间。 IE。 urls[0] 打开正常,但 urls[1] 可能会失败。
在谷歌搜索从 geckodriver.log 中找到的错误消息时,我找到了这个 https://github.com/mozilla/geckodriver/issues/828。由于我没有最大化任何 windows,我不认为我的问题与票证中描述的相同(尽管错误消息显示相似)。
我是 运行 几个 firefox 实例(它们都使用相同的 DISPLAY=:99)。这会不会导致不同的 Firefox 实例相互干扰?
我还应该提到,当我使用 Firefox 44(不需要 Geckodriver)时,这个设置工作得很好。另一件可能很重要的事情是,据我所知,只有当我 运行 使用 Xvfb 的无头浏览器脚本时才会发生这种情况。
正如您从我的问题中看到的那样,我对 Xvfb、Geckodriver 和 Firefox 的了解略有不足。如果有人知道发生了什么,我将不胜感激。
更新:更新到 Geckodriver 0.20.1 解决了问题 - 有点。
问题仍然出现(大约每打开 100 页就会出现一次)。 driver.get(j)
偶尔会失败,但会引发超时错误,可以捕获并处理。