I deployed a flask app with selenium and I installed chromedriver and move to /usr/bin/chromedriver in debian 12 x64 OS. But it’s still errored out. error message:
Traceback (most recent call last):
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
[flight] [2023-11-27 02:54:29] worker.init_process()
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
[flight] [2023-11-27 02:54:29] self.load_wsgi()
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
[flight] [2023-11-27 02:54:29] self.wsgi = self.app.wsgi()
[flight] [2023-11-27 02:54:29] ^^^^^^^^^^^^^^^
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
[flight] [2023-11-27 02:54:29] self.callable = self.load()
[flight] [2023-11-27 02:54:29] ^^^^^^^^^^^
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
[flight] [2023-11-27 02:54:29] return self.load_wsgiapp()
[flight] [2023-11-27 02:54:29] ^^^^^^^^^^^^^^^^^^^
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
[flight] [2023-11-27 02:54:29] return util.import_app(self.app_uri)
[flight] [2023-11-27 02:54:29] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/gunicorn/util.py", line 371, in import_app
[flight] [2023-11-27 02:54:29] mod = importlib.import_module(module)
[flight] [2023-11-27 02:54:29] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/importlib/__init__.py", line 126, in import_module
[flight] [2023-11-27 02:54:29] return _bootstrap._gcd_import(name[level:], package, level)
[flight] [2023-11-27 02:54:29] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[flight] [2023-11-27 02:54:29] File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
[flight] [2023-11-27 02:54:29] File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
[flight] [2023-11-27 02:54:29] File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
[flight] [2023-11-27 02:54:29] File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
[flight] [2023-11-27 02:54:29] File "<frozen importlib._bootstrap_external>", line 940, in exec_module
[flight] [2023-11-27 02:54:29] File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[flight] [2023-11-27 02:54:29] File "/workspace/app.py", line 70, in <module>
[flight] [2023-11-27 02:54:29] driver = webdriver.Chrome(options=option)
[flight] [2023-11-27 02:54:29] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
[flight] [2023-11-27 02:54:29] super().__init__(
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 53, in __init__
[flight] [2023-11-27 02:54:29] self.service.start()
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 102, in start
[flight] [2023-11-27 02:54:29] self.assert_process_still_running()
[flight] [2023-11-27 02:54:29] File "/workspace/.heroku/python/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 115, in assert_process_still_running
[flight] [2023-11-27 02:54:29] raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
[flight] [2023-11-27 02:54:29] selenium.common.exceptions.WebDriverException: Message: Service /workspace/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver unexpectedly exited. Status code was: 127
code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
#service = Service(executable_path='chromedriver.exe')
from selenium.webdriver.chrome.options import Options
option = Options()
#option = webdriver.ChromeOptions()
option.add_argument("--headless=new")
#option.add_argument('--ignore-certificate-errors')
#option.add_argument("--test-type")
#options.binary_location = "/usr/bin/chromium"
#option.add_argument("--no-sandbox")
#option.add_argument('disable-notifications')
#driver = webdriver.Chrome(service=service,options=option)
driver = webdriver.Chrome(options=option)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hello yyz20002008, did you manage to fix the issue. I am facing a similar issue when deploying a flask application that uses selenium for web scrapping.
Heya,
The error message you’re encountering,
selenium.common.exceptions.WebDriverException: Message: Service /workspace/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver unexpectedly exited. Status code was: 127
, suggests a few potential issues with your Selenium setup in your Flask app deployed on a Debian 12 x64 OS. Here are some steps to troubleshoot and potentially resolve the issue:Chromedriver Compatibility: Ensure that the version of
chromedriver
you’re using is compatible with the version of Chrome installed on your system. The error might be due to a version mismatch.Chromedriver Path: The error indicates that Selenium is trying to use a
chromedriver
from a cached path (/workspace/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver
). You need to specify the path to thechromedriver
that you moved to/usr/bin/
. You can do this by uncommenting and modifying theService
line in your code:Permissions and Environment: Ensure that the environment where the Flask app is running has the necessary permissions to execute
chromedriver
and access Google Chrome.Dependencies and Libraries: Make sure that all dependencies and libraries are correctly installed and compatible with each other in your deployment environment.
After making these adjustments, try running your Flask application again. If the problem persists, you may need to look into more detailed logs or error messages for further clues.
Hi there,
I noticed in the output you shared that this might be deployed on the DigitalOcean App Platform. Could you confirm if this is the case?
If your application is indeed running on the App Platform, you would need to manage custom dependencies, like ChromeDriver, differently than on a traditional Droplet. The App Platform uses buildpacks to create your application’s environment, which may not include all the dependencies required for Selenium and ChromeDriver to run properly.
To install custom dependencies, you can define your own environment using a Dockerfile. This allows you to specify exactly what software and versions you need, including Chrome and ChromeDriver. You would then deploy your app using this Dockerfile, which the App Platform will use to build a container for your application:
If this is not the case and you are indeed deploying to a Dropler, setting up the ChromeDriver path in a Debian Droplet for a Selenium-powered Flask application involves a few steps to ensure that the driver can be found and executed properly by your application. The error message you’re seeing suggests that the ChromeDriver is not being executed correctly, possibly because of an incorrect path or missing dependencies.
Install ChromeDriver:
apt
or manually downloading it from the ChromeDriver website.Set the Correct Path:
chromedriver
to/usr/bin/
, it should be executable by just callingchromedriver
from anywhere in your system./usr/bin/
by runningwhich chromedriver
. The output should be/usr/bin/chromedriver
.Set Permissions:
Ensure that the
chromedriver
has the correct permissions set. It should be executable. You can set the permissions using:Update Your Selenium Code:
chromedriver
using theService
object from Selenium. However, if you have placedchromedriver
in/usr/bin/
, this is not necessary as the system should be able to locate it automatically.--headless=new
is not a valid argument. The correct argument for running Chrome in headless mode is--headless
.Here’s an example of how your updated Python code might look:
Install Chrome:
If you haven’t installed Google Chrome, you’ll need to do so as ChromeDriver requires it. You can typically install Google Chrome on Debian with the following commands:
Check for Missing Dependencies:
/usr/bin/chromedriver
) to see if there are any error messages that indicate missing dependencies.Logging:
service_log_path
argument to theService
object in your Selenium code. This can help identify why ChromeDriver is exiting unexpectedly.Let me know how it goes!
Best,
Bobby