Traceback (most recent call last): File "D:\develop\anaconda\lib\site-packages\urllib3\connectionpool.py", line 715, in urlopen httplib_response = self._make_request( File "D:\develop\anaconda\lib\site-packages\urllib3\connectionpool.py", line 404, in _make_request self._validate_conn(conn) File "D:\develop\anaconda\lib\site-packages\urllib3\connectionpool.py", line 1060, in _validate_conn conn.connect() File "D:\develop\anaconda\lib\site-packages\urllib3\connection.py", line 419, in connect self.sock = ssl_wrap_socket( File "D:\develop\anaconda\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket ssl_sock = _ssl_wrap_socket_impl( File "D:\develop\anaconda\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl return ssl_context.wrap_socket(sock, server_hostname=server_hostname) File "D:\develop\anaconda\lib\ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "D:\develop\anaconda\lib\ssl.py", line 1040, in _create self.do_handshake() File "D:\develop\anaconda\lib\ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\develop\anaconda\lib\site-packages\requests\adapters.py", line 667, in send resp = conn.urlopen( File "D:\develop\anaconda\lib\site-packages\urllib3\connectionpool.py", line 801, in urlopen retries = retries.increment( File "D:\develop\anaconda\lib\site-packages\urllib3\util\retry.py", line 594, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /repos/ultralytics/assets/releases/tags/v8.3.0 (Caused by SSLError(SSLCertV
时间: 2025-07-10 18:39:21 浏览: 9
<think>好的,用户遇到了SSLCertVerificationError,具体是CERTIFICATE_VERIFY_FAILED的问题,使用urllib3和requests时出现。我需要先分析可能的原因,然后给出解决方案。
首先,证书验证失败通常有几个原因:证书缺失、系统时间不对、代理干扰、证书过期或不信任。根据引用[1],本地证书找不到,可能是证书路径问题或没有安装。Anaconda用户可能证书配置有问题,或者环境中的OpenSSL版本有问题。引用[2]提到ProxyError的版本号错误,可能代理设置干扰了SSL连接。
接下来,解决方案分步骤。首先建议禁用证书验证作为临时方法,但不推荐长期使用。然后检查系统时间和日期是否正确,因为SSL证书对时间敏感。然后安装或更新证书包,比如使用certifi库。对于Anaconda用户,可能需要手动更新证书或重新安装certifi。如果使用代理,可能需要检查代理配置是否正确,或者添加信任。最后,对于自签名证书的情况,需要禁用验证或手动添加证书。
还需要考虑用户的具体环境,比如是否在公司网络中使用代理,或者是否自定义证书。可能还需要指导用户如何定位证书文件路径,或者如何配置requests库使用指定证书。此外,引用中提到的问题可能与urllib3和requests的版本有关,可能需要升级库或相关依赖。
最后生成相关问题,涵盖常见原因、Anaconda特定问题、代理影响、永久解决方法和requests忽略验证的方法。</think>### SSL证书验证失败问题解决方案
当使用urllib3、requests或Anaconda工具链时出现`SSLCertVerificationError: CERTIFICATE_VERIFY_FAILED`错误,可通过以下步骤排查解决:
---
#### 一、临时解决方案(仅调试用)
在代码中禁用SSL验证(不推荐生产环境):
```python
import requests
response = requests.get('https://api.github.com', verify=False) # 添加verify=False参数
```
*注意:这会降低安全性,可能遭受中间人攻击*
---
#### 二、系统性排查步骤
1. **检查系统时间**
- SSL证书有效期通常精确到秒,系统时间偏差超过5分钟会触发验证失败
- Windows:`控制面板 > 日期和时间 > Internet时间 > 立即更新`
- Linux:`sudo ntpdate pool.ntp.org`
2. **证书安装/更新**
- 手动安装证书包:
```bash
pip install --upgrade certifi
```
- 查找证书路径:
```python
import certifi
print(certifi.where()) # 输出类似 /usr/local/lib/python3.9/site-packages/certifi/cacert.pem
```
3. **Anaconda特殊处理**
```bash
conda update --force conda
conda install -c anaconda openssl
conda clean --all
```
4. **代理配置验证**
- 检查是否因代理导致证书篡改:
```python
proxies = {
"http": "http://user:pass@proxy_ip:port",
"https": "http://user:pass@proxy_ip:port" # 注意此处仍用http协议
}
requests.get(url, proxies=proxies, verify="/path/to/custom/cert.pem")
```
5. **信任特定证书**
```python
import ssl
from urllib3 import PoolManager
class CustomCertSSL(ssl.SSLContext):
def __init__(self):
super().__init__(ssl.PROTOCOL_TLS_CLIENT)
self.load_verify_locations(cafile="/path/to/custom/ca-bundle.crt")
http = PoolManager(ssl_context=CustomCertSSL())
```
---
#### 三、证书链验证原理
SSL验证流程遵循X.509标准:
$$
\begin{aligned}
&\text{验证路径:}\\
&\quad\text{终端实体证书} \rightarrow \text{中间CA证书} \rightarrow \text{根证书}\\
&\text{验证公式:}\\
&\quad\text{签名验证:} \sigma_{\text{CA}}(H_{\text{cert}}) \equiv S \mod N_{\text{CA}}
\end{aligned}
$$
当本地缺少中间CA证书时会导致验证失败[^1]
---
阅读全文
相关推荐













