AI编程生活评测

python中报错SSLCertVerificationError

编程笔记 / 2023-07-13 / 1 min
在使用 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')
点击刷新