Python SSLError语言 - 任何隐藏警告的方法



我在Windows和python3上很wokirng。 我使用请求模块访问带有此代码的网页-

requests.get('https://github.com/')

然后我得到了SSLError [SSL: CERTIFICATE VERIFY FAILED ]错误。然后我关闭了与verify=False进行SSL证书检查的开关。

import requests
requests.get('https://github.com/', verify=False)

现在它正在浏览该网站,但返回警告。

Warning (from warnings module):
File "C:Python27libsite-packagesurllib3connectionpool.py", line 847
InsecureRequestWarning)
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
<Response [200]>

现在我正在使用脚本,我不想向用户显示此警告。我有一种方法可以隐藏警告,但我不确定如何使用它。

warnings.simplefilter("ignore")

但这忽略了所有警告,我只想特别隐藏这个"不安全请求警告"。请指导我如何做到这一点。

所以我得到了隐藏警告的解决方案。这是我所做的。

import warnings
from requests.packages.urllib3.exceptions import InsecureRequestWarning
warnings.simplefilter('ignore',InsecureRequestWarning)
requests.get('https://github.com/',verify=False)

这件事解决了我的问题。

最新更新