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

编程入门 行业动态 更新时间:2024-10-25 10:24:01

[684]requests<a href=https://www.elefans.com/category/jswz/34/1770019.html style=时报错requests.exceptions.SSLError: HTTPSConnectionPool"/>

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

报错信息

raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.baidu', 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('/', 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: .html#ssl-warnings
InsecureRequestWarning)
>>> response.history
[<Response [302]>]
>>> response.url
u'/'

结果出现警告,Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: .html#ssl-warnings InsecureRequestWarning)

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

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

参考:
.html

更多推荐

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

本文发布于:2024-02-11 05:56:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1679505.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时报   requests   HTTPSConnectionPool   SSLError   exceptions

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!