如何解决证书验证失败:无法使用Selenium和ChromeDriverManager获取本地颁发者证书错误

mf98qq94  于 2023-02-08  发布在  其他
关注(0)|答案(1)|浏览(634)

即使有关于这个的大量信息,每个解决方案都不会为我工作,我试图运行一个基本的selenium脚本,我得到这个错误。有没有任何解决方案适合我的情况(注意,我使用3.10 python,我在Windows操作系统下的企业计算机上工作,安装了Zscaler,如果它是有用的)以下是我的代码:

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()

我尝试使用命令(webdriver-manager update --ignore_ssl=true),但我认为我用错了,因为它说webdreiver_manager不是命令。
下面是我得到的整个错误:

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)')))
qvtsj1bj

qvtsj1bj1#

获取(网址:字符串)

    • get(url:str)**只在当前浏览器会话中加载网页,并且只接受url(string)作为参数。因此,如果您尝试传递额外的参数 * verify=False *,则会导致 * TypeError *,如下所示:
TypeError: get() got an unexpected keyword argument 'verify'

verify=False是仅对Python Requests模块有效的参数。请参阅GET and POST requests using Python中的详细信息。

此用例

作为先决条件,您必须安装webdriver-manager并删除 * verify=False * 参数,您的代码在我的windows-10机器上可以完美地执行。

  • 代码块:
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'])
  • 控制台输出:
====== 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

相关问题