Successfully resolve requests and report an error raise SSLError(e, request=request)_requests.exceptions.SSLError_ HTTPSConnectionPool

Problem Description

When using requests to call the https interface, you will encounter an error in the ssl certificate

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

Solutions

Because some websites require a certificate of verification, such as: 12306,
so you only need to add parameters: verify=certificate path, or verify=Flase

Solution

Step 1:
When requests are requested, add the parameter Verify

res1 = requests.post(url=url1, data=data1,verify=False)

However, after adding parameters, there will be a warning, prompting security issues

InsecureRequestWarning: Unverified HTTPS request is being made to host '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

How to ignore the warning?
According to the official urllib3 documentation, you only need to add

import urllib3

urllib3.disable_warnings()

References: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings

Guess you like

Origin blog.csdn.net/AAIT11/article/details/130075038