python
network_error
ai_generated
true
requests.exceptions.SSLError: HTTPSConnectionPool(host='example.com', port=443): 超过最大重试次数 (由SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:主机名不匹配,证书与'example.com'不匹配'))引起)
requests.exceptions.SSLError: HTTPSConnectionPool(host='example.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate does not match 'example.com'')))
ID: python/requests-sslerror-wrong-hostname
80%修复率
85%置信度
0证据数
2024-01-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
服务器的SSL证书是为与正在访问的主机名不同的主机名颁发的。
English
The server's SSL certificate is issued for a different hostname than the one being accessed.
解决方案
-
95% 成功率 Use the correct hostname that matches the certificate's Common Name or Subject Alternative Names
requests.get('https://correct-hostname.com') -
85% 成功率 Provide the certificate via verify parameter if the server uses a custom CA
requests.get('https://example.com', verify='/path/to/custom-ca.pem')
无效尝试
常见但无效的做法:
-
Setting verify=False to ignore SSL verification entirely
70% 失败
Disabling SSL verification exposes the connection to man-in-the-middle attacks and does not solve the hostname mismatch for valid certificates.
-
Updating the requests library to the latest version
90% 失败
The issue is not a library bug but a certificate configuration problem on the server side.