selenium - 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帐户中出现问题,请帮助..
解决方案
此错误消息...
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。
有几个相关的问题如下:
- 如果用户以 root 身份运行 Firefox,但使用他们自己的主目录,那么该用户的许多事情都会被破坏,有时甚至是永久性的。
- 当firefox以root身份运行时,同一显示器上的其他用户可以获得root权限
随着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.)
推荐阅读
- javascript - While fetching details using GET request, 401 error returns
- r - 有没有办法在 for 循环中动态使用已经创建的变量?
- javascript - 是否可以使用 javascript 在邮递员中执行我的 python 脚本?
- python-3.x - 如何使用python处理chrome selenium webdriver的“选择证书”窗口弹出窗口
- node.js - 是否可以在 Node JS 中创建不可删除和可修改的日志文件
- php - 如何获得正确的嵌套 json 格式?
- c++ - 在 Tensorflow C++ API 中访问输出张量时出现 libprotobuf 错误
- azure-cosmosdb - 我可以为 cosmos db 项目使用默认代理吗
- javascript - 使用nodejs + express处理服务器端和客户端错误的最佳方法是什么
- date - 如何在 Elixir 中实现 Date.add(date, n, :month)