如何在请求HTTPS调用中禁止有关缺少证书验证的警告? [英] How to suppress warnings about lack of cert verification in a requests HTTPS call?

查看:339
本文介绍了如何在请求HTTPS调用中禁止有关缺少证书验证的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用有关使用requests的HTTPS调用中缺少证书验证的警告.

I would like to disable the warning about a lack of certificate verification in a HTTPS call using requests.

过去曾有人问过这个问题,导致有关禁用相关请求日志记录 urllib3 SSL警告.

The question has been asked in the past, leading to answers about disabling a relevant request logging or the urllib3 SSL warning.

过去曾经有效(我记得成功地使警告静音),但似乎不再有效了?

This used to work in the past (I remember successfully silencing the warnings) but seems not to work anymore?

我将到目前为止有效的两种解决方案放在一起:

I put together the two solutions which worked so far:

Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
>>> import requests
>>> import requests.packages
>>> import urllib3
>>> urllib3.disable_warnings()
>>> requests.packages.urllib3.disable_warnings()
>>> requests.get('https://www.google.com', verify=False)
/usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: 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
  InsecureRequestWarning)
<Response [200]>

是否有其他(当前)解决方案可以使这些警告静音?

推荐答案

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

有两种不同的方法可以完成这两项工作. 您将不得不将此添加到您的导入中

There are two different ways to do this, both of these work. You will have to add this to your imports

from requests.packages.urllib3.exceptions import InsecureRequestWarning

这篇关于如何在请求HTTPS调用中禁止有关缺少证书验证的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆