gpt4 book ai didi

python - 在几次成功的 Selenium Geckodriver 任务后连接被拒绝(操作系统错误 111)(Python)

转载 作者:行者123 更新时间:2023-12-05 05:56:14 51 4
gpt4 key购买 nike

操作系统:Ubuntu 20.04 无 GUI。

我正在 headless 模式下做一个非常简单的任务:

  1. 安装并启用 firefox 插件。
  2. 导航到 about:debugging#/runtime/this-firefox 并获取插件的 uuid。

问题是,在一些成功的 .py 脚本完成后,下一个脚本会挂起并返回连接被拒绝(操作系统错误 111)错误。之后,我必须重新启动服务器,这只解决了几个 .py 脚本启动的问题。

我的代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver import FirefoxProfile
import time

ff_options = FirefoxOptions()

user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ff/85.0.4183.83 Safari/537.36"

ff_options.add_argument('-headless')
ff_options.add_argument(f'user-agent={user_agent}')
ff_options.add_argument('--disable-dev-shm-usage')
ff_options.add_argument('--no-sandbox')
ff_options.add_argument("--window-size=1920,1080")
ff_options.add_argument('--ignore-certificate-errors')
ff_options.add_argument('--allow-running-insecure-content')
ff_options.add_argument("--proxy-server='direct://'")
ff_options.add_argument("--proxy-bypass-list=*")
ff_options.add_argument("--start-maximized")
ff_options.add_argument('--disable-gpu')
ff_options.add_argument('--disable-setuid-sandbox')

buster = "/root/my_simple_extension.xpi"

driver = webdriver.Firefox(executable_path='/usr/local/share/geckodriver', options=ff_options)
driver.install_addon(buster, temporary=True)
driver.profile = webdriver.FirefoxProfile()
driver.profile.add_extension(buster)
driver.profile.set_preference("security.fileuri.strict_origin_policy", False)
driver.profile.update_preferences()

driver.get("about:debugging#/runtime/this-firefox")

time.sleep(1)

parent1 = driver.find_element_by_xpath('(//div[@class="fieldpair"])[position()=3]')
uuid = parent1.text.splitlines()[1]

driver.get('moz-extension://{}/home.html'.format(uuid))
time.sleep(1)
print(driver.page_source)
driver.quit()

geckodriver.log

1632303683203   geckodriver INFO    Listening on 127.0.0.1:45055
1632303684204 mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "-headless" "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ff/85.0.4183.83 Safari/537.36" "--disable-dev-shm-usage" "--no-sandbox" "--window-size=1920,1080" "--ignore-certificate-errors" "--allow-running-insecure-content" "--proxy-server=\'direct://\'" "--proxy-bypass-list=*" "--start-maximized" "--disable-gpu" "--disable-setuid-sandbox" "-no-remote" "-profile" "/tmp/rust_mozprofilexOejpk"
*** You are running in headless mode.
[GFX1-]: glxtest: Unable to open a connection to the X server
[GFX1-]: glxtest: libEGL missing
1632303684813 Marionette INFO Marionette enabled
[GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at /tmp/rust_mozprofilexOejpk/search.json.mozlz4", (void 0)))
1632303687471 Marionette INFO Listening on port 42933
1632303687541 RemoteAgent WARN TLS certificate errors will be ignored for this session
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/background-8.js, line 17: asm.js type error: expecting argument type declaration for 'e' of the form 'arg = arg|0' or 'arg = +arg' or 'arg = fround(arg)'
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
1632303696737 Marionette INFO Stopped listening on port 42933
Port.onMessage event fired while context is inactive.
Port.onMessage event fired while context is inactive.
Port.onMessage event fired while context is inactive.
JavaScript error: resource:///modules/Interactions.jsm, line 230: NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIUserIdleService.removeIdleObserver]

最佳答案

只有测试的源代码并不能真正帮助为您的问题提供合格的答案。因此请create trace logs在测试运行时与我们分享这些。记录到文件(在您的情况下应该是 geckodriver.log)的附加信息可以帮助了解情况,并最终提出解决方案。谢谢。

关于python - 在几次成功的 Selenium Geckodriver 任务后连接被拒绝(操作系统错误 111)(Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69247047/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com