python2/3 发送https请求时,告警关闭方法

问题:

使用Python3 requests发送HTTPS请求,已经关闭认证(verify=False)情况下,控制台会输出以下错误:

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

 

解决方法:

在代码中添加以下代码即可解决:

1
2
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

 Python2添加如下代码即可解决:

1
2
3
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
posted @ 2018-05-25 14:52  致橡树的你  阅读(1846)  评论(0编辑  收藏  举报