ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.69k stars 1.14k forks source link

UC was able to work before, and got now Cannot connect to chrome at 127.0.0.1:{port changed everytime} from chrome not reachable #670

Closed lancezhaozai closed 2 years ago

lancezhaozai commented 2 years ago

Traceback (most recent call last): File "/home/user/PycharmProjects/S3/testnike.py", line 21, in driver = uc.Chrome(options=chrome_options) File "/home/user/PycharmProjects/S3/venv/lib/python3.9/site-packages/undetected_chromedriver/init.py", line 401, in init super(Chrome, self).init( File "/home/user/PycharmProjects/S3/venv/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in init super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog", File "/home/user/PycharmProjects/S3/venv/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in init RemoteWebDriver.init( File "/home/user/PycharmProjects/S3/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 275, in init self.start_session(capabilities, browser_profile) File "/home/user/PycharmProjects/S3/venv/lib/python3.9/site-packages/undetected_chromedriver/init.py", line 589, in start_session super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session( File "/home/user/PycharmProjects/S3/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 365, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/home/user/PycharmProjects/S3/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 430, in execute self.error_handler.check_response(response) File "/home/user/PycharmProjects/S3/venv/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:48855 from chrome not reachable

the code:

import undetected_chromedriver as uc
import time

chrome_options = uc.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument('--user-data-dir=/home/user/.config/google-chrome')
chrome_options.add_argument("--profile-directory=Profile 3")

driver = uc.Chrome(options=chrome_options)

time.sleep(60)

driver.close()

From chrome://version: Chrome version: 102.0.5005.61 (Official Build) (64-bit) Executable Path | /opt/google/chrome/google-chrome Profile Path | /home/user/.config/google-chrome/Default

undetected-chromedriver==3.1.5.post4

Problem: last night the code was fine, everything work, I able to launch UC directly from python and get pass CF and akamai. but today I restarted my workstation, and have above errors

Scenario 1. UC unable to work totally and shows "Chrome is being controlled by automated test software", and got the above errors

Scenario 2. I launch chrome manually, then launching UC in code, the chrome windows pop without "Chrome is being controlled by automated test software" and works by clicking and input data MANUALLY, but still got above errors

Scenario 3. I change the --user-data-dir=/home/user/.config/google-chrome to --user-data-dir=/home/user/.config/google-chrome/Default, now it cannot get pass CF and akamai

I tried other threads and stackoverflow possible fix in order to overcome this issue but no luck, so I believe yesterday I just got lucky and got pass chrome session and connected it, it seems has something to do with the chrome session like

https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/155

but I cannot find the root cause and get it solve

Edit 1: I had tried old version of chrome and old version of UC, it got even more errors like "The directory is being used", so i decided to step back to last worked code

ultrafunkamsterdam commented 2 years ago

remove your manual options especially profile directory. make sure nothing chrome related is running, so pkill -f google-chome

lancezhaozai commented 2 years ago

remove your manual options especially profile directory. make sure nothing chrome related is running, so pkill -f google-chome

I had removed profile directory and make sure nothing chrome related is alive in system, I had done what you mentioned and yes it did resolved the errors, but wont work for bypassing Akamai and CF, last night I was able to connect to the opened chrome session that I manually launch, and UC able to bypass Akamai and CF perfectly, with profile directory, because profile directory intend to reuse the opened chrome session and connect to it, it works that way last night, but right now it got the error I mentioned

Do you mind I send you everything to reproduce the error and idea? because with UC connected to chrome session, it really works

ultrafunkamsterdam commented 2 years ago

that is in fact what uc does. launching chrome and manually connects to it. it's quite simple here: chrome does not start and therefore uc cannot connect . you need to find out what command line is used by uc (debug=True) then copy it to a terminal and see the output.

oh: you can run only 1 instance per userdatadir .