[英]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.)
In addition to this code it's hosting a flask app for a website which runs with uwsgi
and nginx
.除了此代码之外,它还为使用
uwsgi
和nginx
运行的网站托管了 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.