简体   繁体   English

Selenium:Chrome无法启动:异常退出

[英]Selenium: Chrome failed to start: exited abnormally

I'm trying to make an application with python and selenium but I run into an error.我正在尝试使用 python 和 selenium 制作应用程序,但遇到了错误。 I already searched for a solution and found out that you should add those arguments: --no-sandbox , --headless , --disable-dev-shm-usage which I did but it still didn't work.我已经搜索了一个解决方案,发现你应该添加那些 arguments: --no-sandbox--headless--disable-dev-shm-usage我做了但它仍然没有工作。 The error (full traceback below): selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.错误(下面的完整追溯): selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.

This happens on the initialization of the driver.这发生在驱动程序的初始化时。

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')

driver = webdriver.Chrome("/usr/bin/chromedriver", options=options)

# ...    

Ubuntu Server: 22.04 Ubuntu 服务器:22.04
Python: 3.8 Python:3.8
selenium : 4.3.0 selenium :4.3.0
Google Chrome: 104.0.5112.79 ( https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb )谷歌浏览器:104.0.5112.79( https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Chromedriver: 104.0.5112.79 ( https://chromedriver.storage.googleapis.com/104.0.5112.79/chromedriver_linux64.zip ) Chromedriver:104.0.5112.79( https://chromedriver.storage.googleapis.com/104.0.5112.79/chromedriver_linux64.zip

Location of google-chrome : /usr/bin/google-chrome google-chrome的位置: /usr/bin/google-chrome
Location of chromedriver : /usr/bin/chromedriver chromedriver的位置: /usr/bin/chromedriver

Full traceback:完整追溯:

Traceback (most recent call last):
  File "/home/admini/websites/myapp/./wsgi.py", line 1, in <module>
    from main import app
  File "/home/admini/websites/myapp/./main.py", line 92, in <module>
    sel_driver = SeleniumWebdriver()
  File "/home/admini/websites/myapp/./main.py", line 84, in __init__
    self.driver = init_driver()
  File "/home/admini/websites/myapp/./main.py", line 74, in init_driver
    driver = webdriver.Chrome("/usr/bin/chromedriver", options=options)
  File "/home/admini/websites/myapp/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/home/admini/websites/myapp/venv/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in __init__
    super().__init__(
  File "/home/admini/websites/myapp/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 277, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/admini/websites/myapp/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 370, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/admini/websites/myapp/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 435, in execute
    self.error_handler.check_response(response)
  File "/home/admini/websites/myapp/venv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Edit编辑

In addition to this code it's hosting a flask app for a website which runs with uwsgi and nginx .除了此代码之外,它还为使用uwsginginx运行的网站托管了 flask 应用程序。 I noticed when I run the script, it works.我注意到当我运行脚本时,它可以工作。 However it doesn't when I run it as a service with uwsgi.但是,当我将它作为 uwsgi 的service运行时,它不会。

myapp.ini我的应用程序.ini

[uwsgi]
module = wsgi:app

master = true
processes = 5

socket = myapp.sock
chmod-socket = 660
vacuum = true

die-on-term = true

#location of log files
logto = /var/log/uwsgi/%n.log

/etc/systemd/system/myapp.service /etc/systemd/system/myapp.service

[Unit]
Description=uWSGI instance to serve myapp
After=network.target

[Service]
User=admini
Group=www-data
WorkingDirectory=/home/admini/websites/myapp
Environment="PATH=/home/admini/websites/myapp/venv/bin"
ExecStart=/home/admini/websites/myapp/venv/bin/uwsgi --ini myapp.ini

[Install]
WantedBy=multi-user.target

From https://stackoverflow.com/a/70265091/13508045来自https://stackoverflow.com/a/70265091/13508045

Add :/usr/bin:/bin to your PATH as shown below::/usr/bin:/bin添加到您的 PATH 中,如下所示:

Environment="PATH=/home/admini/websites/myapp/venv/bin:/usr/bin:/bin"

Complete file looks like this:完整的文件如下所示:

[Unit]
Description=uWSGI instance to serve myapp
After=network.target

[Service]
User=admini
Group=www-data
WorkingDirectory=/home/admini/websites/myapp
Environment="PATH=/home/admini/websites/myapp/venv/bin:/usr/bin:/bin"
ExecStart=/home/admini/websites/myapp/venv/bin/uwsgi --ini myapp.ini

[Install]
WantedBy=multi-user.target

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python:Selenium-消息:未知错误:Chrome无法启动:异常退出 - Python : Selenium - Message: unknown error: Chrome failed to start: exited abnormally 未知错误:Chrome 无法启动:异常退出 - Unknown error: Chrome failed to start: exited abnormally selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法启动:使用ChromeDriver Chrome和Selenium异常退出 - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium WebDriverException:消息:未知错误:Chrome 无法启动:通过 VPS 上的 Python 使用 ChromeDriver Chrome 和 Selenium 异常退出 - WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium through Python on VPS WebDriverException:消息:未知错误:Chrome 无法启动:使用 ChromeDriver Chrome 和 Selenium Python 异常退出错误 - WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally error using ChromeDriver Chrome and Selenium Python 设置 selenium 与 headless chrome 错误:WebDriverException:消息:未知错误:Chrome 无法启动:异常退出 - Setup selenium with headless chrome error: WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally WebDriverException:消息:未知错误:Chrome 无法启动:通过 WebDriverManager 使用 Selenium ChromeDriver 和 Chrome 异常退出 - WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally using Selenium ChromeDriver and Chrome through WebDriverManager WebDriverException:消息:未知错误:Chrome 无法启动:在 debian 服务器上使用 ChromeDriver Chrome 和 Selenium 异常退出 - WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium on debian server 无法在容器内启动硒测试,WebDriverException:Chrome 无法启动:异常退出 - Can't launch selenium tests inside container, WebDriverException:Chrome failed to start: exited abnormally Selenium:Chrome 无法启动:异常退出。 DevToolsActivePort 文件不存在 - Selenium: Chrome failed to start: exited abnormally. DevToolsActivePort file doesn't exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM