("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded wit...
🚨 错误信息
'(MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f7abef2f0d0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))"), '(Request ID: 0193b08a-81d9-4796-90c4-bdd86cef8c57)')' thrown while requesting HEAD https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/./modules.json
🤖 AI解决方案
报错分析报告
1. 错误翻译
原文:Max retries exceeded with url: /sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 101] Network is unreachable'))
译文:尝试URL的最大重试次数已超出:/sentence-transformers/all-MiniLM-L6-v2/resolve/main/modules.json (原因是新连接错误:无法建立新连接:[错误号101] 网络不可达)
2. 原因分析
根本原因:网络连接问题导致的HuggingFace模型下载失败
3. 解决方案
#### 方案一:设置代理(如果处于受限网络环境)
python
import os
os.environ['HTTP_PROXY'] = 'http://your-proxy-server:port'
os.environ['HTTPS_PROXY'] = 'https://your-proxy-server:port'
#### 方案二:使用镜像源
python
from sentence_transformers import SentenceTransformer使用国内镜像源(如果可用)
model = SentenceTransformer('all-MiniLM-L6-v2',
cache_folder='/path/to/local/cache')
#### 方案三:增加重试和超时设置
python
from sentence_transformers import SentenceTransformer
import requests自定义会话以增加重试
session = requests.Session()
adapter = requests.adapters.HTTPAdapter(max_retries=3)
session.mount('https://', adapter)try:
model = SentenceTransformer('all-MiniLM-L6-v2',
request_session=session,
timeout=30)
except Exception as e:
print(f"下载失败: {e}")
4. ️ 预防措施
#### 最佳实践建议:
bash
python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
python
import urllib.request
def check_network():
try:
urllib.request.urlopen('https://huggingface.co', timeout=5)
return True
except:
return False
#### 推荐工具:
ping huggingface.co检查网络连通性