解决python爬虫requests.exceptions.SSLError: HTTPSConnectionPool(host=‘XXXXXXX‘, port=443)问题

报错如下 

Traceback (most recent call last):
  File "C:/Users/17653/Desktop/测试.py", line 23, in 
    response = requests.request("POST", url, headers=headers, data=payload)
  File "D:\Python36\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\Python36\lib\site-packages\requests\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\Python36\lib\site-packages\requests\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "D:\Python36\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='xxxxxxx', port=443): Max retries exceeded with url: /view/login.cgi (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))

1.先检查pip有没安装cryptography,pyOpenSSL,certifi要是没有先安装
pip install cryptography
pip install pyOpenSSL
pip install certifi

2.要是以上这些已安装还是继续报错,则在网页请求代码中加上这个 verify=False 就可以解决报错,代码可运行。

response = requests.request("POST", url, headers=headers, data=payload, verify=False)

你可能感兴趣的:(Python爬虫,爬虫,python,pycharm)