Search code examples
pythonseleniumselenium-webdriverwebdriver-managerwebdrivermanager-python

How to address certificate verify failed: unable to get local issuer certificate error using Selenium and ChromeDriverManager


Even with the ton of information about this, each solutions won't work for me, I'm trying to run a basic selenium script and I get this error. Is there any solutions for my case (note that i use 3.10 python and that I'm working on a corporate computer under windows OS which has Zscaler installed, if it is somehow usefull) Here is my code :

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

def openChrome():

    options= Options()
    options.add_experimental_option("detach", True)
    driverweb= webdriver.Chrome(service=Service(ChromeDriverManager().install()), options= options)
    driverweb.get('https://pypi.org/', verify=False)
    driverweb.set_window_size(1000,700)
    driverweb.set_window_position(0,0)

openChrome()

I tried to use the command (webdriver-manager update --ignore_ssl=true) but i think i use it the wrong way cause it is saying that webdreiver_manager isn't a command.

Here is the whole error i get :

Traceback (most recent call last):
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1070, in _create
    self.do_handshake()
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1341, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 489, in send
    resp = conn.urlopen(
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\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: /109.0.5414/chromedriver_win32.zip (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\201046329\Desktop\testwebbrowser.py", line 17, in <module>
    openChrome()
  File "C:\Users\201046329\Desktop\testwebbrowser.py", line 12, in openChrome
    driverweb= webdriver.Chrome(service=Service(ChromeDriverManager().install()), options= options)
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\webdriver_manager\chrome.py", line 39, in install
    driver_path = self._get_driver_path(self.driver)
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\webdriver_manager\core\manager.py", line 30, in _get_driver_path
    file = self._download_manager.download_file(driver.get_url())
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\webdriver_manager\core\download_manager.py", line 28, in download_file
    response = self._http_client.get(url)
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\webdriver_manager\core\http.py", line 32, in get
    resp = requests.get(url=url, verify=self._ssl_verify, stream=True, **kwargs)
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\201046329\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 563, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='chromedriver.storage.googleapis.com', port=443): Max retries exceeded with url: /109.0.5414/chromedriver_win32.zip (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

Solution

  • get(url: str)

    get(url: str) simply loads a web page in the current browser session and accepts only the url (string) as an argument. So if you try to pass the additional parameter verify=False that would result in an TypeError as:

    TypeError: get() got an unexpected keyword argument 'verify'
    

    verify=False is a valid parameter only for the Python Requests module. See details in GET and POST requests using Python.


    This usecase

    As a prerequisite you have to install webdriver-manager and removing the verify=False argument, your code executes perfectly on my box.

    • 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
      
      driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
      driver.get('https://pypi.org/')
      driver.set_window_size(1000,700)
      size = driver.get_window_size()
      print(size['height'], size['width'])
      driver.set_window_position(0,0)
      position = driver.get_window_position()
      print(position['x'], position['y'])
      
    • Console output:

      ====== WebDriver manager ======
      Current google-chrome version is 109.0.5414
      Get LATEST chromedriver version for 109.0.5414 google-chrome
      Driver [C:\Users\user.name\.wdm\drivers\chromedriver\win32\109.0.5414.74\chromedriver.exe] found in cache
      700 1000
      0 0