问题描述
在使用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官方文档可知,只需要添加文章来源:https://www.toymoban.com/news/detail-523644.html
import urllib3
urllib3.disable_warnings()
参考资料:https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings文章来源地址https://www.toymoban.com/news/detail-523644.html
到了这里,关于成功解决requests 报错raise SSLError(e, request=request)_requests.exceptions.SSLError_ HTTPSConnectionPool的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!