问题描述
在使用requests调用https接口时,会遇到ssl证书报错
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='v4.ketangpai.com', port=443): Max retries exceeded with url: /UserApi/login (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)')))
解决思路
因为有的网站需要验证书,比如:12306,
所以只需要加加上参数:verify=证书路径,或verify=Flase
解决方法
步骤1:
在requests请求时,加上参数Verify
res1 = requests.post(url=url1, data=data1,verify=False)
但是,加上参数后,会有警告,提示安全问题
InsecureRequestWarning: Unverified HTTPS request is being made to host '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
如何忽略警告呢?
通过 urllib3官方文档可知,只需要添加
import urllib3
urllib3.disable_warnings()
参考资料:https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
标签:request,urllib3,host,verify,SSLError,requests From: https://www.cnblogs.com/CCX330/p/17292256.html