python使用requests时报错requests.exceptions.SSLError: HTTPSConnectionPool

博客指出出现requests.exceptions.SSLError,是HTTPS连接时证书验证失败。给出了解决办法,可参考相关文档资料,还可通过安装requests依赖包来解决,如cryptography、pyOpenSSL、certifi。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

requests.exceptions.SSLError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)'),))  

 
错误提示就是上面这样的。首先我找了很多的资料,有很多人说关闭证书验证(verify=False))可以解决这个问题或者说是在进行GET时,指定SSL证书.
response = requests.get('http://www.baidu.com/', headers = header, verify=False)  
但我用以上两种方法都没有完美解决此问题,而且有些还有后续错误比如InsecureRequestWarning

 

正确的做法参考文档资料

https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl

参考博客:http://blog.csdn.net/zahuopuboss/article/details/52964809

 

只要安装一下几个requests依赖包就可以解决此问题

 

pip install cryptography 

pip install pyOpenSSL

pip install certifi

 

原文转至博客:https://blog.csdn.net/qq_31077649/article/details/79013199

 

转载于:https://www.cnblogs.com/hum0ro/p/9536033.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值