1

Been knocking my head around persistent problems with trying to get Selenium Web Driver up and running. The following code is what I have. Also sent it to friends and they've been able to run it after installing the mandatory selenium & webdriver-manager files (Same ones I am using).

Seems like this is some kind of networking issue? I've searched round but stuck with limited to zero understanding of networking to make any progress with this issue. I have included the full error log below. If there is anything else I can add let me know.

from selenium import webdriver
from selenium.webdriver.chrome.service import  Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
#options.add_experimental_option("detact", True)

#crashes here on next line
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("https://www.google.com/")

Error Log:

File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connection.py",
line 174, in _new_conn conn = connection.create_connection( File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\util\connection.py",
line 72, in create_connection for res in socket.getaddrinfo(host,
port, family, socket.SOCK_STREAM): File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\socket.py", line 953,
in getaddrinfo for res in _socket.getaddrinfo(host, port, family,
type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connectionpool.py",
line 703, in urlopen httplib_response = self._make_request( File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connectionpool.py",
line 386, in _make_request self._validate_conn(conn) File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connectionpool.py",
line 1040, in _validate_conn conn.connect() File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connection.py",
line 358, in connect self.sock = conn = self._new_conn() File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connection.py",
line 186, in _new_conn raise NewConnectionError(
urllib3.exceptions.NewConnectionError:
<urllib3.connection.HTTPSConnection object at 0x0000023F38A7D7C0>:
Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\requests\adapters.py",
line 489, in send resp = conn.urlopen( File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connectionpool.py",
line 785, in urlopen retries = retries.increment( File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\util\retry.py",
line 592, in increment raise MaxRetryError(_pool, url, error or
ResponseError(cause)) urllib3.exceptions.MaxRetryError:
HTTPSConnectionPool(host='chromedriver.storage.googleapis.com',
port=443): Max retries exceeded with url: /LATEST_RELEASE_114.0.5735
(Caused by NewConnectionError('<urllib3.connection.HTTPSConnection
object at 0x0000023F38A7D7C0>: Failed to establish a new connection:
[Errno 11001] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\requests\api.py",
line 59, in request return session.request(method=method, url=url,
**kwargs) File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\requests\sessions.py",
line 587, in request resp = self.send(prep, **send_kwargs) File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\requests\sessions.py",
line 701, in send r = adapter.send(request, **kwargs) File
"C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\requests\adapters.py",
line 565, in send raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError:
HTTPSConnectionPool(host='chromedriver.storage.googleapis.com',
port=443): Max retries exceeded with url: /LATEST_RELEASE_114.0.5735
(Caused by NewConnectionError('<urllib3.connection.HTTPSConnection
object at 0x0000023F38A7D7C0>: Failed to establish a new connection:
[Errno 11001] getaddrinfo failed'))

Process finished with exit code 1

Any advice appreciated, thank you.

iggy12345
  • 1,233
  • 12
  • 31
  • check this https://stackoverflow.com/questions/7334199/getaddrinfo-failed-what-does-that-mean sounds like you might be using a proxy – iggy12345 Jun 13 '23 at 15:12

2 Answers2

1

Not that super clear where you are exactly stuck. However on my box with v3.9.0, Selenium v4.8.0 and WebDriverManager v3.5.2 the below program executes just perfecto:

  • Code block:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    import sys
    
    print ("Python Version: " +sys.version)
    import webdriver_manager
    print("WebDriverManager version: " +webdriver_manager.__version__)
    import selenium
    print("Selenium version: " +selenium.__version__)
    options = Options()
    options.add_argument("start-maximized")
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
    driver.get('https://pypi.org/')
    
  • Console output:

    Python Version: 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
    WebDriverManager version: 3.5.2
    Selenium version: 4.8.0
    
    
    ====== WebDriver manager ======
    Current google-chrome version is 114.0.5735
    Get LATEST chromedriver version for 114.0.5735 google-chrome
    Driver [C:\Users\fnmae.lname\.wdm\drivers\chromedriver\win32\114.0.5735.90\chromedriver.exe] found in cache
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hey, output; "webdriver version = 3.7.0" / "selenium version = 4.1.2" Crashed at same line: driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) once more with the exact same error as above. Perhaps version issue or? – Callum Kent Jun 14 '23 at 13:07
1

If you're using selenium 4.10.0 or newer, then the driver manager is already included. This code will handle that, and be compatible with any platform:

import sys
import time
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--disable-notifications")
options.add_argument("--disable-gpu")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
if "linux" in sys.platform:
    options.add_argument("--headless=new")
options.add_experimental_option(
    "excludeSwitches", ["enable-automation", "enable-logging"],
)
driver = webdriver.Chrome(options=options)
driver.get("https://www.google.com/")
time.sleep(1)
driver.quit()
Michael Mintz
  • 9,007
  • 6
  • 31
  • 48