python network_error ai_generated true

httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:证书不受信任 (_ssl.c:1123),连接到'https://untrusted.example.com'时

httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate is not trusted (_ssl.c:1123) while connecting to 'https://untrusted.example.com'

ID: python/httpx-connecterror-ssl-certificate-verify-failed-untrusted

其他格式: JSON · Markdown 中文 · English
80%修复率
86%置信度
0证据数
2025-08-15首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

服务器的证书由系统不信任的CA签名。

English

The server's certificate is signed by a CA that is not trusted by the system.

generic

解决方案

  1. 90% 成功率 Properly install the CA certificate in the system trust store
    # On Windows: import the .crt file into 'Trusted Root Certification Authorities'
    # On macOS: sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ca.crt
  2. 85% 成功率 Use the verify parameter with the CA certificate file
    httpx.get('https://untrusted.example.com', verify='/path/to/ca.crt')

无效尝试

常见但无效的做法:

  1. Adding the certificate to the system trust store incorrectly 70% 失败

    Improper installation may still not make it trusted.

  2. Using verify=False as a permanent solution 60% 失败

    Disables security and is not recommended for production.