首页 > 解决方案 > selenium.common.exceptions.WebDriverException:消息:进程意外关闭,状态为 1

问题描述

版本:firefox:Mozilla Firefox 61.0 geckodriver:geckodriver v0.20.1

我只试过下面的代码:

from selenium import webdriver

browser = webdriver.Firefox()

但得到如下错误:

Traceback (most recent call last):
  File "my.py", line 3, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
keep_alive=True)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 245, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 314, in execute
self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-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

和 geckodriver.log:

1528101123327 geckodriver INFO geckodriver 0.20.1

1528101123336 geckodriver INFO 监听 127.0.0.1:43481

1528101124336 mozrunner::runner INFO 运行命令:“/usr/bin/firefox”“-marionette”“-profile”“/tmp/rust_mozprofile.y93GPXwtXuKC”

不支持在常规用户会话中以 root 身份运行 Firefox。($XAUTHORITY 是 /home/username/.Xauthority,归用户名所有。)

这只是在root帐户中出现问题,请帮助..

标签: seleniumfirefoxwebdrivergeckodriver

解决方案


此错误消息...

Running Firefox as root in a regular user's session is not supported. ($XAUTHORITY is /home/keti/.Xauthority which is owned by keti.)

...意味着您要么尝试以 root 用户身份调用Firefox Browser ,要么在非 root 会话root用户身份运行Firefox Browser

根据用户的 Firefox 进程以 root 身份运行(如果 root 正在运行 Firefox),这两种情况都不受支持,并且应该相对难以实现。但从技术上讲,它仍然是可能的(因为 --new-instance 和 --no-remote 标志可用于控制远程控制)但 X11 的许可安全模型意味着用户应该基本上将用户帐户视为无密码 sudo。

有几个相关的问题如下:

随着Firefox v60.0的 GA(通用可用性), Mozilla 团队决定禁止 Firefox 以 sudo身份运行,如下所示:

  • 对沙盒 Linux 进程使用 clone() 而不是 fork() 并删除 SandboxEarlyInit 等。
  • 之前运行的sudo firefox以前似乎可以工作但不受支持,现在将无法在大多数Linux 发行版上加载内容(任何页面上的选项卡崩溃),并且将无法启动并打印如下消息:

    Running Firefox as root in a regular user's session is not supported. ($XAUTHORITY is /home/username/.Xauthority which is owned by username.)
    

推荐阅读