Source From Here
Question
因为想做一个爬虫定时领取淘宝的淘金币,无奈在使用 requests 获取页面内容时,收到了错误提示:
How-To
根据 Google 到的结果,解决方案如下:
如下是 urllib3 文档的说明:
- InsecurePlatformWarning
2016年03月02日更新:
先附加一个官方的链接:
https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning
之所以更新是因为,我在virutalenv的环境下,使用pip安装第三方包时,也遇到了类似的提示:
然而这种时候我是不可能去修改代码的,那么解决方案就在官方链接中的最后一部分:
Disabling Warnings
Making unverified HTTPS requests is strongly discouraged. ˙ ͜ʟ˙ But if you understand the ramifications and still want to do it...
Within the code
If you know what you’re doing and would like to disable all urllib3 warnings, you can use disable_warnings():
Alternatively, if you are using Python’s
logging module, you can capture the warnings to your own log:
Capturing the warnings to your own log is much preferred over simply disabling the warnings.
Without modifying code
If you are using a program that uses urllib3 and don’t want to change the code, you can suppress warnings by setting the PYTHONWARNINGS environment variable in Python 2.7+ or by using the -W flag with the Python interpreter (see docs), such as:
Question
因为想做一个爬虫定时领取淘宝的淘金币,无奈在使用 requests 获取页面内容时,收到了错误提示:
How-To
根据 Google 到的结果,解决方案如下:
如下是 urllib3 文档的说明:
- InsecurePlatformWarning
2016年03月02日更新:
先附加一个官方的链接:
https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning
之所以更新是因为,我在virutalenv的环境下,使用pip安装第三方包时,也遇到了类似的提示:
然而这种时候我是不可能去修改代码的,那么解决方案就在官方链接中的最后一部分:
Disabling Warnings
Making unverified HTTPS requests is strongly discouraged. ˙ ͜ʟ˙ But if you understand the ramifications and still want to do it...
Within the code
If you know what you’re doing and would like to disable all urllib3 warnings, you can use disable_warnings():
- import urllib3
- urllib3.disable_warnings()
- logging.captureWarnings(True)
Without modifying code
If you are using a program that uses urllib3 and don’t want to change the code, you can suppress warnings by setting the PYTHONWARNINGS environment variable in Python 2.7+ or by using the -W flag with the Python interpreter (see docs), such as:
沒有留言:
張貼留言