Forums

Chrome driver not working

I tried everything but I am just getting this error this is not happening in my local pc.

import undetected_chromedriver as uc
from undetected_chromedriver import ChromeOptions
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
options = ChromeOptions()
options.add_argument("--disable-extensions")
options.add_argument('--disable-application-cache')
options.add_argument('--disable-gpu')
options.add_argument("--no-sandbox")
options.add_argument("--disable-setuid-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--incognito") 
driver = uc.Chrome(options=options)
driver.get('https://google.com/')
Traceback (most recent call last):
  File "/home/mefor/main.py", line 19, in <module>
    main()
  File "/home/mefor/main.py", line 16, in main
    login()
  File "/home/mefor/login.py", line 23, in login
    driver = uc.Chrome(options=options)
  File "/home/mefor/.local/lib/python3.10/site-packages/undetected_chromedriver/__init__.py", line 466, in __init__
    super(Chrome, self).__init__(
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 61, in __init__
    super().__init__(command_executor=executor, options=options)
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 208, in __init__
    self.start_session(capabilities)
  File "/home/mefor/.local/lib/python3.10/site-packages/undetected_chromedriver/__init__.py", line 724, in start_session
    super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, 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:59965
from chrome not reachable
Stacktrace:
#0 0x564bfe487d93 <unknown>
#1 0x564bfe16b177 <unknown>
#2 0x564bfe15602a <unknown>
#3 0x564bfe1a4cf8 <unknown>
#4 0x564bfe19b1cb <unknown>
#5 0x564bfe1e5b7c <unknown>
#6 0x564bfe1d91e3 <unknown>
#7 0x564bfe1a9135 <unknown>
#8 0x564bfe1aa13e <unknown>
#9 0x564bfe44be4b <unknown>
#10 0x564bfe44fdfa <unknown>
#11 0x564bfe4386d5 <unknown>
#12 0x564bfe450a6f <unknown>
#13 0x564bfe41c69f <unknown>
#14 0x564bfe475098 <unknown>
#15 0x564bfe475262 <unknown>
#16 0x564bfe486f34 <unknown>
#17 0x7fe1e5f2b609 start_thread

You may be starting too many browsers at a time, we recommend wrapping the browser calls in:

try:
    browser.get("https://www.google.com")
    print("Page title was '{}'".format(browser.title))
finally:
    browser.quit()

so your code would always clean up when the job is done.

Here is my updated code. Works perfectly on local machine but in pythonanywhere I am getting error.

Code:

from seleniumbase import Driver
driver = Driver(uc=True, headless=True, no_sandbox=True, disable_gpu=True)

    try:
        driver.get('https://google.com/')
        print("Page title was '{}'".format(driver.title))
    finally:
        driver.quit()

Error:

Traceback (most recent call last):
  File "/home/mefor/.local/lib/python3.10/site-packages/seleniumbase/core/browser_launcher.py", line 3478, in get_local_driver
    driver = undetected.Chrome(
  File "/home/mefor/.local/lib/python3.10/site-packages/seleniumbase/undetected/__init__.py", line 312, in __init__
    super().__init__(options=options, service=service_)
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 61, in __init__
    super().__init__(command_executor=executor, options=options)
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 208, in __init__
    self.start_session(capabilities)
  File "/home/mefor/.local/lib/python3.10/site-packages/seleniumbase/undetected/__init__.py", line 448, in start_session
    super().start_session(capabilities)
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "/home/mefor/.local/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, 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:9222
from chrome not reachable
Stacktrace:
#0 0x55e81748be89 <unknown>

Enable some features in my account.

What features? There are no disabled features related to that.

Hey,

Any luck in getting this work. I am facing also facing error in making the seleniumbase library work in pythonanywhere.

Which error are you getting exactly? (I believe we've already replied you in a different thread -- please keep one communication channel to avoid confusion.)