解决:InsecureRequestWarning: Unverified HTTPS request is being made to host ‘www.xxx.cn’. Adding certificate verification is strongly advised.
背景
在使用之前的代码时,报错:D:/Anaconda_soft/envs/pytorch/lib/site-packages/urllib3/connectionpool.py:1043:
InsecureRequestWarning: Unverified HTTPS request is being made to host ‘www.dytt89.com’.
Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
报错问题
D:/Anaconda_soft/envs/pytorch/lib/site-packages/urllib3/connectionpool.py:1043:
InsecureRequestWarning: Unverified HTTPS request is being made to host 'www.dytt89.com'.
Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
报错翻译
主要报错信息内容翻译如下所示:
D:/Anaconda_soft/envs/pytorch/lib/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning:
Unverified HTTPS request is being made to host 'www.dytt89.com'.
Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
翻译:
D: /Anaconda_soft/env/pytorch/lib/site-packages/urlib3/connectionpool.py:1043:
不安全请求警告:正在向主机“www.dytt89.com”发出未经验证的HTTPS请求。
强烈建议添加证书验证。请参阅:https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-警告
报错位置代码
res = requests.get(url, headers=headers, verify=False, params=params)
报错原因
经过查阅资料,发现这个错误产生的原因是证书的验证问题,即我们设置了去掉安全验证的选项(verify=False
),因为设置跳过了SSL证书验证,程序本身不具有代码逻辑相关问题,感兴趣的读者可以去看官方文档: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
。
小伙伴们按下面的解决方法即可解决!!!
解决方法
要解决这个错误,这里总结了以下几个解决办法。
方法一
在程序开始部分添加代码,禁用或忽略警告。
正确的代码是:
requests.packages.urllib3.disable_warnings()
或者
warnings.filterwarnings(‘ignore’)
方法二
导入warnings包进行处理
正确的代码如下:文章来源:https://www.toymoban.com/news/detail-789396.html
import urllib3
http = urllib3.PoolManager(num_pools=50)
今天的分享就到此结束了
文章来源地址https://www.toymoban.com/news/detail-789396.html
到了这里,关于解决:InsecureRequestWarning:Unverified HTTPS request is being made to host ‘xx.cn’. Adding ......的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!