成功解决requests 报错raise SSLError(e, request=request)_requests.exceptions.SSLError_ HTTPSConnectionPool(host='v4.ketangpai.com',
问题描述
在使用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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!