-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Seleniumbase in docker with cdp mode and proxy #3662
-
Hello! I am working on a scraper. It is working totally fine on ubuntu 22.04, but once i tried to run it in docker container with your Dockerfile and http proxy="user:pass@host:port" i got an error:
"selenium.common.exceptions.SessionNotCreatedException: Message: session not created: cannot connect to chrome at 127.0.0.1:9222
from chrome not reachable"
in short:
- ubuntu 22.04 + sb 4.36.1 + proxy is working
- docker with Dockerfile without proxy is working
- docker with Dockerfile and with proxy is not working
I will be glad for any help how to use proxy inside docker container
with SB(uc=True, incognito=True, xvfb=True, xvfb_metrics="1920,1080", proxy="user:pass@host:port") as sb:
sb.activate_cdp_mode(URL)
...
full traceback
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/seleniumbase/core/browser_launcher.py", line 5161, in get_local_driver
driver = undetected.Chrome(
File "/usr/local/lib/python3.10/dist-packages/seleniumbase/undetected/__init__.py", line 316, in __init__
super().__init__(options=options, service=service_)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
super().__init__(
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/chromium/webdriver.py", line 66, in __init__
super().__init__(command_executor=executor, options=options)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 250, in __init__
self.start_session(capabilities)
File "/usr/local/lib/python3.10/dist-packages/seleniumbase/undetected/__init__.py", line 529, in start_session
super().start_session(capabilities)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 342, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.10/dist-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 0x5f6d6c9d8e6a <unknown>
#1 0x5f6d6c48a493 <unknown>
#2 0x5f6d6c475523 <unknown>
#3 0x5f6d6c4c98bc <unknown>
#4 0x5f6d6c4bf5d3 <unknown>
#5 0x5f6d6c5100ce <unknown>
#6 0x5f6d6c50f5f6 <unknown>
#7 0x5f6d6c501523 <unknown>
#8 0x5f6d6c4cdef3 <unknown>
#9 0x5f6d6c4ceb51 <unknown>
#10 0x5f6d6c99dd2b <unknown>
#11 0x5f6d6c9a1c01 <unknown>
#12 0x5f6d6c985512 <unknown>
#13 0x5f6d6c9a2774 <unknown>
#14 0x5f6d6c96990f <unknown>
#15 0x5f6d6c9c6fb8 <unknown>
#16 0x5f6d6c9c7196 <unknown>
#17 0x5f6d6c9d7cb6 <unknown>
#18 0x75d2fc1a0ac3 <unknown>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/_pimeyes_scrapper/src/main_sb_cdp.py", line 227, in <module>
main(
File "/_pimeyes_scrapper/src/main_sb_cdp.py", line 182, in main
with SB(
File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.10/dist-packages/seleniumbase/plugins/sb_manager.py", line 1269, in SB
sb.setUp()
File "/usr/local/lib/python3.10/dist-packages/seleniumbase/fixtures/base_case.py", line 15272, in setUp
self.driver = self.get_new_driver(
File "/usr/local/lib/python3.10/dist-packages/seleniumbase/fixtures/base_case.py", line 4212, in get_new_driver
new_driver = browser_launcher.get_driver(
File "/usr/local/lib/python3.10/dist-packages/seleniumbase/core/browser_launcher.py", line 3134, in get_driver
return get_local_driver(
File "/usr/local/lib/python3.10/dist-packages/seleniumbase/core/browser_launcher.py", line 5185, in get_local_driver
driver = undetected.Chrome(
File "/usr/local/lib/python3.10/dist-packages/seleniumbase/undetected/__init__.py", line 316, in __init__
super().__init__(options=options, service=service_)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
super().__init__(
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/chromium/webdriver.py", line 66, in __init__
super().__init__(command_executor=executor, options=options)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 250, in __init__
self.start_session(capabilities)
File "/usr/local/lib/python3.10/dist-packages/seleniumbase/undetected/__init__.py", line 529, in start_session
super().start_session(capabilities)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 342, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.10/dist-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 0x5728eecc2e6a <unknown>
#1 0x5728ee774493 <unknown>
#2 0x5728ee75f523 <unknown>
#3 0x5728ee7b38bc <unknown>
#4 0x5728ee7a95d3 <unknown>
#5 0x5728ee7fa0ce <unknown>
#6 0x5728ee7f95f6 <unknown>
#7 0x5728ee7eb523 <unknown>
#8 0x5728ee7b7ef3 <unknown>
#9 0x5728ee7b8b51 <unknown>
#10 0x5728eec87d2b <unknown>
#11 0x5728eec8bc01 <unknown>
#12 0x5728eec6f512 <unknown>
#13 0x5728eec8c774 <unknown>
#14 0x5728eec5390f <unknown>
#15 0x5728eecb0fb8 <unknown>
#16 0x5728eecb1196 <unknown>
#17 0x5728eecc1cb6 <unknown>
#18 0x735512615ac3 <unknown>
Beta Was this translation helpful? Give feedback.
All reactions
"session not created: cannot connect to chrome at 127.0.0.1:9222"
and "from chrome not reachable"
generally mean that Chrome is not in the default location. Set it with the binary_location
arg.
Also, Docker leaves a fingerprint, so it's not compatible with UC Mode / CDP Mode. The included Dockerfile is only intended for regular SeleniumBase use (not for stealth). Use regular Ubuntu Linux (without Docker) for UC Mode / CDP Mode.
Replies: 1 comment
-
"session not created: cannot connect to chrome at 127.0.0.1:9222"
and "from chrome not reachable"
generally mean that Chrome is not in the default location. Set it with the binary_location
arg.
Also, Docker leaves a fingerprint, so it's not compatible with UC Mode / CDP Mode. The included Dockerfile is only intended for regular SeleniumBase use (not for stealth). Use regular Ubuntu Linux (without Docker) for UC Mode / CDP Mode.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2