python3中Requests将verify设置为False后,取消警告的方式

发布时间 2023-04-09 21:15:12作者: 帅胡
import requests
resp = requests.get('https://www.***.com', verify=False)

调用成功但是会有如下警告信息:

InsecureRequestWarning: Unverified HTTPS request is being made to host 'www.jhnews.com.cn'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
warnings.warn(

 

 

解决方法一:

import requests
logging.captureWarnings(True)

解决方法二:

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