python network_error ai_generated true

httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1123),连接到'https://internal.example.com'时

httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123) while connecting to 'https://internal.example.com'

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

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

版本兼容性

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

根因分析

服务器的证书链不完整或本地未安装CA证书。

English

The server's certificate chain is incomplete or the CA certificate is not installed locally.

generic

解决方案

  1. 90% 成功率 Install the missing CA certificate in the system trust store
    # On Linux: sudo cp ca.crt /usr/local/share/ca-certificates/ && sudo update-ca-certificates
    # Then use httpx normally
  2. 85% 成功率 Provide the CA certificate file via the verify parameter
    httpx.get('https://internal.example.com', verify='/path/to/ca.crt')

无效尝试

常见但无效的做法:

  1. Disabling SSL verification entirely 70% 失败

    Compromises security and does not address the missing CA.

  2. Using a different SSL library 90% 失败

    The issue is with the certificate, not the library.