python-3.x - Selenium Python (3.141.0, Geckodriver 0.30.0) 无法打开 Firefox Webdriver:“您的 Firefox 配置文件无法加载它可能丢失或无法访问。”
问题描述
已修复:在将 Ubuntu 21.04 升级到 21.10 firefox(之前使用 apt 安装)时,已删除并使用 snap-version 安装。反转(卸载快照版本并使用 apt 重新安装)这解决了我的问题。
在再次升级 dist 后,我不得不将 firefox 重置为默认浏览器后,我应该进行调查。
在尝试使用 Selenium for Python 创建 Firefox Webdriver 时,我收到以下消息: “无法加载您的 Firefox 配置文件它可能丢失或无法访问。” 单击“确定”后,将出现以下堆栈跟踪:
>>> foo = webdriver.Firefox()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
这在升级到 Ubuntu 21.10(从 21.04)之前没有发生,但我不知道是什么导致了这个错误。手动尝试使用旧的 Geckodriver (0.29.1) 创建驱动程序也不起作用,并导致相同的错误:
$ ./geckodriver.bup -V
geckodriver 0.29.1 (970ef713fe58 2021-04-08 23:34 +0200)
The source code of this program is available from
testing/geckodriver in https://hg.mozilla.org/mozilla-central.
This program is subject to the terms of the Mozilla Public License 2.0.
You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.
$ python3
Python 3.9.7 (default, Sep 10 2021, 14:59:43)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> foo = webdriver.Firefox(executable_path=r'./geckodriver.bup')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/jonathan/.local/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
我唯一肯定改变的是 python 版本(从 3.9.5 到 3.9.7,但是使用带有 3.9.5 的 python-venv 会产生相同的错误)。
我遗漏了一个明显的错误吗?
软件版本/日志:
$ cat geckodriver.log
1635171867200 geckodriver INFO Listening on 127.0.0.1:37079
1635171867204 mozrunner::runner INFO Running command: "/snap/bin/firefox" "--marionette" "-no-remote" "-profile" "/tmp/rust_mozprofileZ5vGbH"
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
amdgpu: os_same_file_description couldn't determine if two DRM fds reference the same file description.
If they do, bad things may happen!
$ geckodriver -V
geckodriver 0.30.0 (d372710b98a6 2021-09-16 10:29 +0300)
The source code of this program is available from
testing/geckodriver in https://hg.mozilla.org/mozilla-central.
This program is subject to the terms of the Mozilla Public License 2.0.
You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.
$ firefox -V
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Mozilla Firefox 93.0
$ pip freeze | grep selenium
selenium==3.141.0
(e:尝试使用 selenium==4.0.0 也不起作用)
$ python3 -V
Python 3.9.7
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 21.10"
NAME="Ubuntu"
VERSION_ID="21.10"
VERSION="21.10 (Impish Indri)"
VERSION_CODENAME=impish
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=impish
e2:我怀疑错误与创建的临时配置文件的权限有关。但是在“/tmp/”中创建的配置文件看起来很干净。它们始终设置为当前用户。使用例如手动指定它们
foo = webdriver.Firefox(firefox_profile=r'/tmp/rust_mozprofile7nswon')
返回相同的错误(“无法加载您的 Firefox 配置文件。它可能丢失或无法访问。”)。
解决方案
tl;dr:重新安装 firefox(卸载 snap 包并使用 apt 安装)解决了这个问题。
我把SiKings 的评论放在心上,唯一的答案提到“如果您的 Web 浏览器基础版本太旧,请通过 Revo Uninstaller 卸载 Web 浏览器并安装最近 GA 发布的 Web 浏览器版本。” 所以我重新安装了firefox,随后解决了这个问题。
版本没有改变:
$ firefox -V
Mozilla Firefox 93.0
我认为这很可能是 dist 升级引起的权限问题。
推荐阅读
- python - Pandas 读取 CSV 缺失行
- spyne - Python - Spyne RPC 工具包有什么招摇的吗?
- azure-devops - 如何在 Azure DevOps 中删除不需要的工件
- javascript - 使用标准 Javascript 的 Deck.gl HexagonLayer 工具提示
- javascript - SyntaxError:使用 Firebase 时出现意外的标识符
- python - 将字符串转换为字典
- javascript - ActionCodeSettings 未在电子邮件发送的链接中更新
- android - 在 Firebase 文档中的列表开头插入新的孩子
- excel - VB.Net COMException 尝试将数据从一个 Excel 文档粘贴到另一个
- flutter - 如何减少 Flutter Web 应用程序的加载时间