Skip to content

yet another SessionNotCreatedException: Message: session not created: cannot connect to chrome at 127.0.0.1:9222 #3675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lambdina opened this issue Apr 15, 2025 · 4 comments
Labels
duplicate The answer/solution already exists somewhere UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@lambdina
Copy link

Hi,
Trying to do some scraping for a client. Trying to run seleniumbase on a remote server. Works fine locally with macos.
I tried it all, look for discussions, issues, and tried all of the following fixes:

  • my google chrome is on the right path and I installed it manually, both with snap and by downolading the binary
$ whereis google-chrome google-chrome-stable chromedriver
google-chrome: /usr/bin/google-chrome /usr/share/man/man1/google-chrome.1.gz
google-chrome-stable: /usr/bin/google-chrome-stable /usr/share/man/man1/google-chrome-stable.1.gz
chromedriver:

So no chromedriver but I already entered sbase get chromedriver and even though it is not opart of my PATH variable I think seleniumbase is managing it fine (path was saved to /home/***/venv/lib/python3.12/site-packages/seleniumbase/drivers/)

Here is how I initialize my driver =

with SB(uc=True, locale_code='fr', xvfb=True, headless2=False, ad_block=True) as sb:

both by trying to set binary_location at default path or non default path when downloading it manually.
I need to have headless at False otherwise I am detected as a bot or the page does not fully load, I don't really know but it does not scrape anything.

Here are the chrome version used:
chromedriver 135.0.7049.84
Google Chrome 135.0.7049.84

Here is the full Trace :
start error

X11 display failed! Will use regular xvfb!
INFO: 127.0.0.1:50536 - "POST /api/v1/scraping/old_scraping HTTP/1.1" 500 Internal Server Error
ERROR: Exception in ASGI application

  • Exception Group Traceback (most recent call last):
    | File "/home/cbulte/Moodee-preprod/backend/app/api/v1/handlers/scraping.py", line 60, in create_and_launch_scraping
    | return await ScrapingService.launch_scraping(scraping, focus_id)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/home/cbulte/Moodee-preprod/backend/app/services/scraping_service.py", line 315, in launch_scraping
    | await ScrapingLauncher().launch_scraping_and_update_status(scraping.scraping_id, scraping_data, focus_id)
    | File "/home/cbulte/Moodee-preprod/backend/app/services/scraping_service.py", line 457, in launch_scraping_and_update_status
    | async with asyncio.TaskGroup() as tg:
    | ^^^^^^^^^^^^^^^^^^^
    | File "/usr/lib/python3.12/asyncio/taskgroups.py", line 71, in aexit
    | return await self.aexit(et, exc)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/usr/lib/python3.12/asyncio/taskgroups.py", line 164, in aexit
    | raise BaseExceptionGroup(
    | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
    +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/seleniumbase/core/browser_launcher.py", line 5162, in get_local_driver
    | driver = undetected.Chrome(
    | ^^^^^^^^^^^^^^^^^^
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/seleniumbase/undetected/init.py", line 316, in init
    | super().init(options=options, service=service
    )
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in init
    | super().init(
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/chromium/webdriver.py", line 66, in init
    | super().init(command_executor=executor, options=options)
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 250, in init
    | self.start_session(capabilities)
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/seleniumbase/undetected/init.py", line 545, in start_session
    | super().start_session(capabilities)
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 342, in start_session
    | response = self.execute(Command.NEW_SESSION, caps)["value"]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
    | self.error_handler.check_response(response)
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
    | raise exception_class(message, screen, stacktrace)
    | selenium.common.exceptions.SessionNotCreatedException: Message: session not created: cannot connect to chrome at 127.0.0.1:9222
    | from chrome not reachable
    | Stacktrace:
    | #0 0x556123336d0a
    | Clean large files from history #1 0x556122de7443
    | Welcome to https://pypi.python.org/pypi/seleniumbase/ #2 0x556122dd24d3
    | Add test logs to show what the logging system provides #3 0x556122e2686c
    | Run Chrome tests in Docker #4 0x556122e1c593
    | Update flake8 and then deflake #5 0x556122e6cf9e
    | Demo Mode for SeleniumBase #6 0x556122e6c4c6
    | Make headless browser automation easier #7 0x556122e5e433
    | Add Google Cloud Jenkins integration #8 0x556122e2aea3
    | Integrations Organization #9 0x556122e2bb01
    | Upgrade to Selenium 2.50.0 (SeleniumBase 1.1.21) #10 0x5561232fbb5b
    | Selenium Grid overhaul #11 0x5561232ffa41
    | Break out ReadMe into smaller help docs #12 0x5561232e2c52
    | DB reporting plugin for pytest #13 0x5561233005b4
    | S3 plugin for pytest #14 0x5561232c6f0f
    | Nosetest logging defaults #15 0x556123324db8
    | Tidy up pytest config #16 0x556123324f96
    | Upgrade requirements #17 0x556123335b56
    | Grid hub update #18 0x7f3b0da9eac3
    |
    |
    | During handling of the above exception, another exception occurred:
    |
    | Traceback (most recent call last):
    | File "/home/cbulte/Moodee-preprod/backend/app/services/scraping_service.py", line 674, in launch_scraping_amazon_reviews
    | df = self.amazon.scrape_amazon_reviews(keyword_list, data.start_date)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/home/cbulte/Moodee-preprod/backend/app/services/sources/scraping_amazon_reviews.py", line 172, in scrape_amazon_reviews
    | with SB(browser='chrome', uc=True, locale_code='fr', xvfb=True, headless2=False, ad_block=True, binary_location='/home/cbulte/Moodee-preprod/backend/chrome-linux64/chrome') as sb:
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/usr/lib/python3.12/contextlib.py", line 137, in enter
    | return next(self.gen)
    | ^^^^^^^^^^^^^^
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/seleniumbase/plugins/sb_manager.py", line 1269, in SB
    | sb.setUp()
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/seleniumbase/fixtures/base_case.py", line 15299, in setUp
    | self.driver = self.get_new_driver(
    | ^^^^^^^^^^^^^^^^^^^^
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/seleniumbase/fixtures/base_case.py", line 4232, in get_new_driver
    | new_driver = browser_launcher.get_driver(
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/seleniumbase/core/browser_launcher.py", line 3135, in get_driver
    | return get_local_driver(
    | ^^^^^^^^^^^^^^^^^
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/seleniumbase/core/browser_launcher.py", line 5186, in get_local_driver
    | driver = undetected.Chrome(
    | ^^^^^^^^^^^^^^^^^^
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/seleniumbase/undetected/init.py", line 316, in init
    | super().init(options=options, service=service
    )
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in init
    | super().init(
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/chromium/webdriver.py", line 66, in init
    | super().init(command_executor=executor, options=options)
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 250, in init
    | self.start_session(capabilities)
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/seleniumbase/undetected/init.py", line 545, in start_session
    | super().start_session(capabilities)
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 342, in start_session
    | response = self.execute(Command.NEW_SESSION, caps)["value"]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
    | self.error_handler.check_response(response)
    | File "/home/cbulte/Moodee-preprod/backend/venv/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
    | raise exception_class(message, screen, stacktrace)
    | selenium.common.exceptions.SessionNotCreatedException: Message: session not created: cannot connect to chrome at 127.0.0.1:9222
    | from chrome not reachable
    | Stacktrace:
    | #0 0x557c6a39dd0a
    | Clean large files from history #1 0x557c69e4e443
    | Welcome to https://pypi.python.org/pypi/seleniumbase/ #2 0x557c69e394d3
    | Add test logs to show what the logging system provides #3 0x557c69e8d86c
    | Run Chrome tests in Docker #4 0x557c69e83593
    | Update flake8 and then deflake #5 0x557c69ed3f9e
    | Demo Mode for SeleniumBase #6 0x557c69ed34c6
    | Make headless browser automation easier #7 0x557c69ec5433
    | Add Google Cloud Jenkins integration #8 0x557c69e91ea3
    | Integrations Organization #9 0x557c69e92b01
    | Upgrade to Selenium 2.50.0 (SeleniumBase 1.1.21) #10 0x557c6a362b5b
    | Selenium Grid overhaul #11 0x557c6a366a41
    | Break out ReadMe into smaller help docs #12 0x557c6a349c52
    | DB reporting plugin for pytest #13 0x557c6a3675b4
    | S3 plugin for pytest #14 0x557c6a32df0f
    | Nosetest logging defaults #15 0x557c6a38bdb8
    | Tidy up pytest config #16 0x557c6a38bf96
    | Upgrade requirements #17 0x557c6a39cb56
    | Grid hub update #18 0x7f2bbb97fac3

Please enlighten me on how can I debug more, it's been days, don't flag it as "not reproducible or invalid usage" because I just don't know what to do anymore. Any question that might help you help me ?
Thanks

@lambdina
Copy link
Author

Ok I removed uc=True and it worked...

@mdmintz mdmintz added duplicate The answer/solution already exists somewhere UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Apr 15, 2025
@mdmintz
Copy link
Member

mdmintz commented Apr 15, 2025

For the X11 display failed!, that's a duplicate of #3060 and #2982.

Check the following to find out if your Linux distribution is missing X11 display dependencies:


For the other error, that's a duplicate of #3370 (comment).

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.

@mdmintz mdmintz closed this as completed Apr 15, 2025
@lambdina
Copy link
Author

Dear @mdmintz , thank you for your reply and your work. Have you read the issue content until the end ? As I mentioned in the top, I already tried seeing the other issues you mentioned without success. I also tried adding binary_location with both google-chrome and google-chrome-stable. It is not working, unless I put uc=False. May you please reopen the issue ?
Thanks.

@mdmintz
Copy link
Member

mdmintz commented Apr 17, 2025

You said you saw X11 display failed!. That means you're missing at least one Linux dependency. (Or you're missing Linux permissions.)

Check the following to find out if your Linux distribution is missing X11 display dependencies:

Or, switch to a Linux distribution that already has all the dependencies installed.
SeleniumBase works well in GitHub Actions Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate The answer/solution already exists somewhere UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants