Selenium Python(3.141.0,Geckodriver 0.30.0)无法打开 Firefox Webdriver:"Your Firefox profile cannot be loaded It may be missing or inaccessible."
Selenium Python (3.141.0, Geckodriver 0.30.0) can't open Firefox Webdriver: "Your Firefox profile cannot be loaded It may be missing or inaccessible."
已修复:在将 Ubuntu 21.04 升级到 21.10 时,firefox(之前使用 apt 安装)被删除并与 snap-version 一起安装。
反向(卸载 snap 版本并使用 apt 重新安装)这解决了我的问题。
我应该在 dist-upgrade 后再次将 firefox 重置为默认浏览器后进行调查。
尝试使用 Selenium 为 Python I get greeted with the following: 创建 Firefox Webdriver 时“无法加载您的 Firefox 配置文件,它可能已丢失或无法访问。”
单击 'ok' 后,将出现以下堆栈跟踪:
>>> 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,但是使用 python-venv 和 3.9.5 会产生相同的错误) .
我是否遗漏了一个明显的错误?
Software-Versions/logs:
$ 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')
returns同样的错误('Your Firefox profile cannot be loaded. It may be missing or inaccessible.').
下载 firefox 网络驱动程序:https://github.com/mozilla/geckodriver/releases
然后将文件解压到默认目录
tar -C /usr/local/bin/ -xvf geckodriver-v0.30.0-linux64.tar.gz
将选择的 geckodriver 目录添加到 PATH
export PATH=$PATH:/YourDirectory
创建 python 文件 main.py
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://google.com/')
运行 python main.py
试试这个方法可能对你有帮助
tl;dr:重新安装 firefox(卸载 snap 包并使用 apt 安装)解决了问题。
我牢记 ,唯一的答案提到“如果您的 Web 浏览器基础版本太旧,请通过 Revo Uninstaller 卸载 Web 浏览器并安装最新发布的 GA 版本的 Web 浏览器。”所以我重新安装了 firefox,随后解决了这个问题。
版本没有变化:
$ firefox -V
Mozilla Firefox 93.0
我认为这很可能是 dist 升级导致的权限问题。
已修复:在将 Ubuntu 21.04 升级到 21.10 时,firefox(之前使用 apt 安装)被删除并与 snap-version 一起安装。 反向(卸载 snap 版本并使用 apt 重新安装)这解决了我的问题。
我应该在 dist-upgrade 后再次将 firefox 重置为默认浏览器后进行调查。
尝试使用 Selenium 为 Python I get greeted with the following: 创建 Firefox Webdriver 时“无法加载您的 Firefox 配置文件,它可能已丢失或无法访问。” 单击 'ok' 后,将出现以下堆栈跟踪:
>>> 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,但是使用 python-venv 和 3.9.5 会产生相同的错误) .
我是否遗漏了一个明显的错误?
Software-Versions/logs:
$ 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')
returns同样的错误('Your Firefox profile cannot be loaded. It may be missing or inaccessible.').
下载 firefox 网络驱动程序:https://github.com/mozilla/geckodriver/releases
然后将文件解压到默认目录
tar -C /usr/local/bin/ -xvf geckodriver-v0.30.0-linux64.tar.gz
将选择的 geckodriver 目录添加到 PATH
export PATH=$PATH:/YourDirectory
创建 python 文件 main.py
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://google.com/')
运行 python main.py
试试这个方法可能对你有帮助
tl;dr:重新安装 firefox(卸载 snap 包并使用 apt 安装)解决了问题。
我牢记
版本没有变化:
$ firefox -V
Mozilla Firefox 93.0
我认为这很可能是 dist 升级导致的权限问题。