【Python】Unresolved reference 'InsecureRequestWarning' Inspection info: This inspecti

在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

安装完之后,保存

 

待续

posted @ 2019-07-02 15:57  念槐聚  阅读(967)  评论(0)    收藏  举报