在Pycharm中导入包的时候,会存在报错问题:
Unresolved reference 'InsecureRequestWarning' less... (Ctrl+F1)
Inspection info: This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items
如下
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
解决InsecureRequestWarning警告
不要使用verify=False
或者requests.packages.urllib3.disable_warnings()
不要忽视警告
尝试过这几种:
在语句前增加
requests.packages.urllib3.disable_warnings()
# 导入包时导入
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# python3
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# python2
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
正确的做法
参考
https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl
Certificate verification
It is highly recommended to always use SSL certificate verification.By default, urllib3 does not verify HTTPS requests.
In order to enable verification you will need a set of root certificates. The easiestand most reliable method is to use thecertifi package which provides Mozilla’s root certificate bundle:
pip install certifi
安装几个包
pip install cryptography
pip install pyOpenSSL
pip install certifi
我这机器同时安装了Python2 和 Python3 ,可以采取一下方式安装:
D:\CODE\WORK_TEST\YHCode\PreEnv>py -2 "C:\Python27\Scripts\pip.exe" install certifi
D:\CODE\WORK_TEST\YHCode\PreEnv>py -2 "C:\Python27\Scripts\pip.exe" install cryptography
D:\CODE\WORK_TEST\YHCode\PreEnv>py -2 "C:\Python27\Scripts\pip.exe" install pyOpenSSL
安装完之后,保存
待续
赠人玫瑰
手留余香
我们曾如此渴望命运的波澜,到最后才发现:人生最曼妙的风景,竟是内心的淡定与从容……我们曾如此期盼外界的认可,到最后才知道:世界是自己的,与他人毫无关系!-杨绛先生