Official Document Reference Address:
Https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
Different levels of warnings are available for SSL warnings,urllib3 based on different levels of certificate validation, and there are several different workarounds for these different scenarios
1. Unsafe Request Warning
This happens when a request is made to the HTTPS URL without enabling certificate validation. The solution is as follows:
Reference official Address: Https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl
URLLIB3 does not validate the Htpps request, in order to enable certificate authentication, a set of root certificates is required, the simplest and most realistic implementation is to use the Certifi package, which contains the Mozilla root certificate package
Installation method: 1), pip install Certifi or 2), Pip install Urllib3[secure]
Once installed, you can create poolmanager for certificate validation when sending a request
#_*_ encoding:utf-8 _*_ImportRequestsImportURLLIB3ImportCertifihttp=URLLIB3. Poolmanager (Cert_reqs='cert_required', Ca_certs=certifi.where ())#no exceptionHttp.request ('GET','https://www.baidu.com/')#have an exceptionHttp.request ('GET','https://expired.badssl.com')#urllib3.exceptions.MaxRetryError:HTTPSConnectionPool (host= ' expired.badssl.com ', port=443): Max retries Exceeded with URL:/(Caused by Sslerror (Sslerror (1, U ' [ssl:certificate_verify_failed] CERTIFICATE VERIFY FAILED (_ssl.c: 661), ))#The error is as followsR = Requests.get ('https://www.baidu.com/')#requests.exceptions.SSLError:HTTPSConnectionPool (host= ' www.baidu.com ', port=443): Max retries exceeded with URL: /(Caused by Sslerror (Sslerror (1,
U ' [ssl:certificate_verify_failed] CERTIFICATE VERIFY FAILED (_ssl.c:661) '),) )
2. Unsafe Platform Warning
This happens on a Python 2 platform with outdated SSL modules. These old SSL modules can lead to insecure requests that succeed where they fail and request failure where they should succeed. Follow the PYOPENSSL guidelines to resolve this warning.
Official document reference address: Https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl-py2
PYOPENSSL Official Address: https://pyopenssl.readthedocs.io/en/latest/
3.SNIMissingWarning
This happens on Python version 2, larger than 2.7.9. These older versions lack the support of SNI. This may cause the server to display certificates that the customer considers invalid. Follow the PYOPENSSL guidelines to resolve this warning.
Note: If you are sure that the HTTPS request is secure and accessible, you can suppress the warning in the following ways
Import urllib3urllib3.disable_warnings ()
#同时可以通过以下方式抓取日志
Logging.capturewarnings (True)
Python Interface Automation--ssl 3