You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am experiencing an issue where the SeleniumBase Driver initialization works perfectly when the code is executed manually using python3, or when Flask is run manually. However, when the Flask app is integrated with Gunicorn and Nginx for automatic startup, the driver initialization fails with the following error:
Error loading driver: Message: session not created: cannot connect to chrome at 127.0.0.1:9222
from chrome not reachable
The issue arises when trying to initialize the Driver or SB (SeleniumBase) with undetectable Chrome in headless mode.
Send a POST request using curl or Postman to the /fetch endpoint.
The driver loads successfully, and the page title is returned.
Configure Flask with Gunicorn and Nginx:
Set up Gunicorn and Nginx to start the Flask app automatically (as per typical production setups).
Start the server and send a POST request to the /fetch endpoint.
Error Observed:
The request fails with the error:
Error loading driver: Message: session not created: cannot connect to chrome at 127.0.0.1:9222
from chrome not reachable
Observations:
The driver works fine when the script is run manually or when Flask is started manually.
The issue occurs only when Flask is served with Gunicorn and Nginx.
Environment Details:
SeleniumBase Version: 4.33.12
Flask Version: 3.1.0
Gunicorn Version: 23.0.0
Ubuntu Version: 22.04.4 LTS (Jammy Jellyfish)
Nginx Version: 1.18.0
Python Version: 3.10.12
What I Have Tried:
Verified that the environment variables are correctly set in the gunicorn.service file, including:
PATH
Chrome driver binary path
Added a virtual display (xvfb) for headless mode.
Used the uc=True parameter with SeleniumBaseSB and Driver.
Increased the timeout duration.
Switched the Gunicorn worker class to gthread.
Verified that all required dependencies are installed.
Checked system resources (sufficient memory and CPU available).
Tested the code outside Gunicorn (both manually and with Flask), and it worked as expected.
I have used selenium for some websites which works as expected
Additional Context:
The issue seems related to Gunicorn's process management or Nginx's proxy setup interfering with the uc=True argument or the headless Chrome browser session. Further guidance on resolving this issue is appreciated.
The text was updated successfully, but these errors were encountered:
Error loading driver: Message: session not created: cannot connect to chrome at 127.0.0.1:9222 from chrome not reachable
That usually means Chrome is not in the default location for the OS being used, so you must set it manually with binary_location. Eg: binary_location="/usr/bin/google-chrome". Figure out where Chrome is located, and then set it. Note that on Linux, you'll need to use either google-chrome-stable or google-chrome (but NOT chromium).
Other possible reasons may include port conflicts if multithreading, or missing Linux permissions.
Note that the point of xvfb is so that you don't have to use headless Chrome, which is detectable.
Description:
I am experiencing an issue where the SeleniumBase
Driver
initialization works perfectly when the code is executed manually usingpython3
, or when Flask is run manually. However, when the Flask app is integrated with Gunicorn and Nginx for automatic startup, the driver initialization fails with the following error:The issue arises when trying to initialize the
Driver
orSB
(SeleniumBase
) withundetectable
Chrome in headless mode.Steps to Reproduce:
Create a Python script (
test.py
):Run the script manually:
python3 test.py
.Add the same functionality in a Flask app:
Run Flask manually:
python3 app.py
.POST
request usingcurl
or Postman to the/fetch
endpoint.Configure Flask with Gunicorn and Nginx:
POST
request to the/fetch
endpoint.Error Observed:
Observations:
Environment Details:
What I Have Tried:
gunicorn.service
file, including:PATH
xvfb
) for headless mode.uc=True
parameter withSeleniumBase
SB
andDriver
.gthread
.Additional Context:
The issue seems related to Gunicorn's process management or Nginx's proxy setup interfering with the
uc=True
argument or the headless Chrome browser session. Further guidance on resolving this issue is appreciated.The text was updated successfully, but these errors were encountered: