EOF occurred in violation of protocol (_ssl.c python3.7 使用代理报错

关掉代理 或者

应该是urllib3的版本问题,安装下面这个版本
pip install urllib3==1.25.11

ubuntu@ubuntu:~$ pip install protobuf==3.20.3 Defaulting to user installation because normal site-packages is not writeable WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1007)'))': /simple/protobuf/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1007)'))': /simple/protobuf/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1007)'))': /simple/protobuf/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1007)'))': /simple/protobuf/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1007)'))': /simple/protobuf/ Could not fetch URL https://pypi.org/simple/protobuf/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/protobuf/ (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1007)'))) - skipping ERROR: Could not find a version that satisfies the requirement protobuf==3.20.3 (from versions: none) ERROR: No matching distribution found for protobuf==3.20.3
03-14
### SSL EOF Error 和最大重试次数限制的解决方案 当遇到 `SSL EOF` 错误并超过最大重试次数时,通常表明客户端与服务器之间的安全连接存在问题。以下是可能的原因及其对应的解决方法: #### 可能原因分析 1. **网络不稳定或中断** 如果网络连接在传输过程中被意外切断,则可能导致 `EOF` 错误。这种情况下,建议优化网络环境或者增加超时时间来减少因短暂断连引发的问题[^3]。 2. **证书配置不正确** 客户端使用SSL/TLS 证书可能已过期、无效或未被信任。验证服务端提供的 CA 根证书是否最新,并确认其已被正确安装到系统的受信存储库中[^4]。 3. **协议版本兼容性问题** 若双方支持的不同 TLS 版本之间存在差异(如一方仅支持较旧版而另一方强制使用新版),则会触发握手失败。可以通过调整应用层设置允许更广泛的协议范围来缓解此冲突[^5]。 4. **资源耗尽情况下的异常行为** 当系统内存不足或其他硬件资源接近饱和状态时也可能表现出类似的症状。监控运行状况指标可以帮助识别潜在瓶颈所在位置[^6]。 #### 解决方案实施步骤说明 尽管题目要求避免描述具体操作流程,但仍需提及几个关键方面以便全面解答该类技术难题: - 更新依赖库至最新稳定版本以获取修复补丁; - 修改应用程序代码逻辑提高鲁棒性和容错能力; - 配置代理中间件实现负载均衡从而分散压力源; 下面给出一段 Python 示例程序展示如何自定义 requests 库中的适配器参数来自定义 HTTPS 连接选项: ```python import ssl from urllib3 import PoolManager from requests.adapters import HTTPAdapter from requests.sessions import Session class CustomHTTPAdapter(HTTPAdapter): def init_poolmanager(self, connections, maxsize, block=False): context = ssl.create_default_context() # Allow older protocols if necessary (not recommended for production!) context.options |= ssl.OP_NO_TLSv1_3 | ssl.OP_NO_TLSv1_2 self.poolmanager = PoolManager( num_pools=connections, maxsize=maxsize, block=block, ssl_version=context.protocol ) session = Session() adapter = CustomHTTPAdapter() # Mount adapter to both http:// and https:// URLs. for prefix in ('http://', 'https://'): session.mount(prefix, adapter) response = session.get('https://example.com') print(response.status_code) ``` 上述脚本通过继承默认的 `HTTPAdapter` 类实现了定制化的池管理功能,在初始化阶段指定所需的加密套件以及禁用了部分现代标准以适应特殊场景需求。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值