By yyz20002008
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!
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 calling chromedriver from anywhere in your system./usr/bin/ by running which 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:
sudo chmod +x /usr/bin/chromedriver
Update Your Selenium Code:
chromedriver using the Service object from Selenium. However, if you have placed chromedriver 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:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option = Options()
option.add_argument("--headless") # Correct argument for headless mode
# Ensure Chrome is installed and update the binary_location if necessary
# option.binary_location = "/usr/bin/google-chrome"
driver = webdriver.Chrome(options=option)
# Your code to use `driver` goes here
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:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
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 the Service object in your Selenium code. This can help identify why ChromeDriver is exiting unexpectedly.Let me know how it goes!
Best,
Bobby
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 the chromedriver that you moved to /usr/bin/. You can do this by uncommenting and modifying the Service line in your code:
service = Service(executable_path='/usr/bin/chromedriver')
driver = webdriver.Chrome(service=service, options=option)
option.add_argument("--headless")
option.add_argument("--no-sandbox")
option.add_argument("--disable-dev-shm-usage")
option.binary_location = "/path/to/google-chrome"
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.
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.