Python Interface Automation--ssl 3

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.