Exactly what the title says. When ran, Chrome does in fact open, but does not continue on because unable to connect. Prints
opening chrome (mac)
opened chrome
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 378, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, 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:9515
from chrome not reachable
Stacktrace:
When I run chromedriver
in terminal it successfully starts and returns
Starting ChromeDriver 110.0.5481.77 () on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Current version of Chrome is 110.0.5481.100
Code is as follows
def open_chrome(port=9515, on_mac=True):
my_env = os.environ.copy()
if on_mac:
print('opening chrome (Mac)')
subprocess.Popen(['open', '-a', "Google Chrome", "--args",
f'--remote-debugging-port={port}', 'http://www.example.com']) # , env=venv)
else:
print('opening chrome (Linux)')
subprocess.Popen(
f'google-chrome --remote-debugging-port={port} --user-data-dir=data_dir'.split(), env=venv)
print('opened chrome')
class Bot():
def __init__(self, port_no=9515, headless=False, verbose=False):
print('initialising bot')
options = Options()
if headless:
options.add_arguments("--headless")
else:
open_chrome()
# attatch to the same port that you're running chrome on
options.add_experimental_option(
f"debuggerAddress", f"127.0.0.1:{port_no}")
# without this, the chrome webdriver can't start (SECURITY RISK)
options.add_argument("--no-sandbox")
# options.add_arguement("--window-size=1920x1080")
self.driver = webdriver.Chrome(options=options)
self.verbose = verbose
echo $PATH
returns
/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Most of the stuff I can find on similar problems suggest PATH issue but because running chromedriver
is successful I don't think it's PATH problem? But also not sure since I don't see it in $PATH
...