我在 Windows 和 python3 上工作。我使用请求模块访问带有此代码的网页-
requests.get('https://github.com/')
然后我得到了SSLError [SSL: CERTIFICATE VERIFY FAILED ]错误。然后我关闭了 SSL 证书检查的开关verify=False。
import requests
requests.get('https://github.com/', verify=False)
Run Code Online (Sandbox Code Playgroud)
现在它正在浏览网站但返回警告。
Warning (from warnings module):
File "C:\Python27\lib\site-packages\urllib3\connectionpool.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]>
Run Code Online (Sandbox Code Playgroud)
现在我正在使用一个脚本,我不想向用户显示此警告。我有一种隐藏警告的方法,但我不确定如何使用它。
warnings.simplefilter("ignore")
Run Code Online (Sandbox Code Playgroud)
但这忽略了所有警告,我只想特别隐藏这个“InsecureRequestWarning”。请指导我如何做到这一点。