[684]requests时报错requests.exceptions.SSLError: HTTPSConnectionPool

报错信息

raise SSLError(e, request=request)
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)'),))

分析:由于报错SSL证书验证失败,所以这次的访问应该是https协议.但是我们明明使用的是http,所以,猜测访问该网站后,被重定向到了https

解决:关闭证书验证.因为,如果不关闭,请求总是失败,不能获取到重定向的信息.

安装一下几个requests依赖包,然后设置, verify=False

pip install cryptography 
pip install pyOpenSSL
pip install certifi
>>> response = requests.get('http://www.baidu.com/', headers = header, verify=False)
D:\python\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
>>> response.history
[<Response [302]>]
>>> response.url
u'https://www.baidu.com/'

结果出现警告,Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning)

想去掉红框内的内容还需要添加如下代码

# requests.packages.urllib3.disable_warnings()

from requests.packages.urllib3.exceptions import InsecureRequestWarning	
#关闭安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

参考:https://blog.csdn.net/win_turn/article/details/77142100
https://www.cnblogs.com/hum0ro/p/9536033.html
https://blog.csdn.net/jss19940414/article/details/89886043
https://blog.csdn.net/weixin_42081389/article/details/90261719

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周小董

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值