python中报错SSLCertVerificationError

在使用requesthttps发送请求时出现报错:

requests.exceptions.SSLError: HTTPSConnectionPool(host='xxx.com', port=443): Max retries exceeded with url: /api/skill/ (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'xxx.com'. (_ssl.c:997)")))

这个是由于SSL验证导致:

两种方法解决

  1. 加入verify=False跳过验证:
r = requests.get(url, verify=False)
  1. 传递包含受信任 CA 证书的CA_BUNDLE文件或目录的路径:
r = requests.get(url, verify='/path/to/certfile')
python中报错SSLCertVerificationError

原文链接:https://beltxman.com/3912.html,若无特殊说明本站内容为 行星带 原创,未经同意禁止转载。

发表评论

您的电子邮箱地址不会被公开。

Scroll to top