本文主要是介绍接口自动化,证书异常:requests.exceptions.SSLError: HTTPSConnectionPool,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、问题:
在做接口自动化的时候,报错:
requests.exceptions.SSLError: HTTPSConnectionPool(host='staffssoapi123', port=443): Max retries exceeded with url:
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='staffssoapi123.baid', port=443): Max retries exceeded with url: /login (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)')))
二、解决办法:
1、在requests请求中,加 :verify=False
ret = requests.post(url, data=json.dumps(params), headers=headers,verify=False).json()
结果:requests发送成功,但是会报warmings
InsecureRequestWarning: Unverified HTTPS request is being made to host 'staffssoapi'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warningswarnings.warn(
2、消除warmings,导入:
import urllib3 urllib3.disable_warnings()
import requests,json
import urllib3
urllib3.disable_warnings()
结果:requests发送成功,没有warmings
这篇关于接口自动化,证书异常:requests.exceptions.SSLError: HTTPSConnectionPool的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!