Python SSL certificate verification solution

Time:2021-1-26

This article mainly introduces the solution of Python SSL certificate verification problem, which is introduced in great detail through the example code. It has a certain reference learning value for everyone’s study or work, and friends who need it can refer to it

1、 SSL issues

1. When you don’t enable fiddler, the Python code will send the HTTPS request directly, and there will be no SSL problem (that is, if you don’t want to see the SSL problem, just turn off Fiddler)

2. If Fiddler is enabled, the following errors will be reported:


raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='163.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))

Verify parameter settings

1. Verify = true by default for requests

2. If you set verify to false, requests can also ignore the verification of SSL certificates

3. But there will still be two lines of warning, which can be ignored

Python 3 prompts warning to add any of the following three codes to solve the problem:

Mode 1:


import requests
requests.packages.urllib3.disable_warnings

Mode 2:


import warnings
warnings.filterwarnings("ignore")

Mode 3:


import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.