You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 21.10升级后Selenium启动Firefox Webdriver提示配置文件无法加载

问题根因已修复

Ubuntu 21.04升级至21.10的过程中,系统会自动移除此前通过apt安装的Firefox,替换为snap版本。卸载snap版Firefox后重新通过apt安装即可解决问题。如果你在发行版升级后需要反复将Firefox设置为默认浏览器,就应该优先排查该问题。

我在发行版升级后需要重设Firefox为默认浏览器时,没有提前排查该原因,才触发了后续的问题。


使用Python的Selenium库创建Firefox Webdriver实例时,弹出报错:Your Firefox profile cannot be loaded It may be missing or inaccessible.,点击确认后输出如下堆栈跟踪:

>>> 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.04升级到21.10后首次出现,升级前运行完全正常,暂时无法定位错误原因。尝试使用旧版Geckodriver 0.29.1创建驱动实例仍返回相同错误:

$ ./geckodriver.bup -V
geckodriver 0.29.1 (970ef713fe58 2021-04-08 23:34 +0200)

$ 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 3.9.5的虚拟环境运行仍可复现该错误,暂无明确排查方向。
软件版本与相关日志如下:

$ 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)
$ 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

补充:尝试升级到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

后续补充排查:怀疑错误由自动生成的临时配置文件权限问题导致,但/tmp目录下生成的配置文件权限均归属当前用户,手动指定配置文件路径如下仍返回相同错误:

foo = webdriver.Firefox(firefox_profile=r'/tmp/rust_mozprofile7nswon')

内容的提问来源于stack exchange,提问作者Jonathan Gerdes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 14:54:03