python的https请求移除ssl验证警告

运行python的 https 请求时,经常出现 warning 信息,

usr/lib/python2.7/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.255.135'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
hello, django https # 返回内容

如果不想看到,我们可以做如下设置:

python代码

#!/usr/bin/python

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
 
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # 忽略警告

url = 'https://192.168.255.135:8443/hello'

res = requests.get(url=url, verify=False) # https时,增加verify=False

print res.content

再次运行程序:

# ./test.py
# hello, django https

posted on 2021-02-19 16:46  进击的davis  阅读(342)  评论(0)    收藏  举报

导航