简体   繁体   中英

SSL Certificate Verification Failed - When using WebDriverManager in Python Selenium framework

I am using Python Selenium framework. In here, to launch the chrome browser, instead of giving chrome binary (chrome.exe) path, I am trying to use WebdriverManager to get the latest version of Chrome driver (based on browser version). Below is the code for that -

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time

driver = webdriver.Chrome(ChromeDriverManager().install())

driver.get("https://google.com")
time.sleep(2)
driver.close()

When I run this file, I get SSL Verification error. Below is the Console output -

[WDM] - 

[WDM] - ====== WebDriver manager ======
[WDM] - Current google-chrome version is 94.0.4606
[WDM] - Get LATEST driver version for 94.0.4606
Traceback (most recent call last):
File "C:\KBApps\Python38\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "C:\KBApps\Python38\lib\site-packages\urllib3\connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "C:\KBApps\Python38\lib\site-packages\urllib3\connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "C:\KBApps\Python38\lib\site-packages\urllib3\connection.py", line 416, in connect
self.sock = ssl_wrap_socket(
File "C:\KBApps\Python38\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\KBApps\Python38\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:\KBApps\Python38\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\KBApps\Python38\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\KBApps\Python38\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\KBApps\Python38\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\KBApps\Python38\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "C:\KBApps\Python38\lib\site-packages\urllib3\util\retry.py", line 574, 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_94.0.4606 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/sainim/PycharmProjects/API_TestCMD/API_Test/driverDemo.py", line 5, in <module>
driver = webdriver.Chrome(ChromeDriverManager().install())
File "C:\KBApps\Python38\lib\site-packages\webdriver_manager\chrome.py", line 34, in install
driver_path = self._get_driver_path(self.driver)
File "C:\KBApps\Python38\lib\site-packages\webdriver_manager\manager.py", line 23, in _get_driver_path
driver_version = driver.get_version()
File "C:\KBApps\Python38\lib\site-packages\webdriver_manager\driver.py", line 41, in get_version
return self.get_latest_release_version()
File "C:\KBApps\Python38\lib\site-packages\webdriver_manager\driver.py", line 64, in get_latest_release_version
resp = requests.get(f"{self._latest_release_url}_{self.browser_version}")
File "C:\KBApps\Python38\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\KBApps\Python38\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\KBApps\Python38\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\KBApps\Python38\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\KBApps\Python38\lib\site-packages\requests\adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='chromedriver.storage.googleapis.com', port=443): Max retries exceeded with url: /LATEST_RELEASE_94.0.4606 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')))

Process finished with exit code 1

I have tried updating webdriver-manager, requests, urllib3 using pip. But it doesn't work.

Rootcause: That's an issue of your VPN/Proxy or corporate network.

webdriver-manager is not the cause.

There are two solutions:

  1. install valid certificates in your certificate chain, check common october 2021 ssl problem with certificates
  2. webdriver-manager will have solution soon - a feature to disable SSL verification in next release 3.5.2 (today is 3.5.1), this feature is already in master branch, see CHANGELOG .

WDM_SSL_VERIFY SSL verification can be disabled for downloading webdriver binaries in case when you have troubles with SSL Certificates or SSL Certificate Chain. Just set the environment variable WDM_SSL_VERIFY to "0".

import os

os.environ['WDM_SSL_VERIFY'] = '0'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM