# requests.exceptions.SSLError: HTTPSConnectionPool(host='example.com', port=443): 超过最大重试次数 (由SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败：主机名不匹配，证书与'example.com'不匹配'))引起)

- **ID:** `python/requests-sslerror-wrong-hostname`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

服务器的SSL证书是为与正在访问的主机名不同的主机名颁发的。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Use the correct hostname that matches the certificate's Common Name or Subject Alternative Names** (95% 成功率)
   ```
   requests.get('https://correct-hostname.com')
   ```
2. **Provide the certificate via verify parameter if the server uses a custom CA** (85% 成功率)
   ```
   requests.get('https://example.com', verify='/path/to/custom-ca.pem')
   ```

## 无效尝试

- **Setting verify=False to ignore SSL verification entirely** — Disabling SSL verification exposes the connection to man-in-the-middle attacks and does not solve the hostname mismatch for valid certificates. (70% 失败率)
- **Updating the requests library to the latest version** — The issue is not a library bug but a certificate configuration problem on the server side. (90% 失败率)
