LLM call failed: HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Read timed...
错误信息
LLM call failed: HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Read timed out. (read timeout=60)
AI 解决方案
报错分析报告
1.错误翻译
原文:HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Read timed out. (read timeout=60)
译文:HTTPS连接池(主机:'www.dmxapi.cn',端口:443):读取超时。(读取超时时间=60秒)
2. 原因分析
www.dmxapi.cn:443建立HTTPS连接后,60秒内未收到服务器响应数据,触发读取超时。3.解决方案
以Python
requests库为例,通过增加超时时间+重试机制修复:import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
# 1. 创建带重试的Session
session = requests.Session()
retry_strategy = Retry(
total=3, # 总重试次数
backoff_factor=1, # 重试间隔(1s, 2s, 4s...)
status_forcelist=[429, 500, 502, 503, 504], # 需重试的状态码
allowed_methods=["GET", "POST"] # 允许重试的方法
)
adapter = HTTPAdapter(max_retries=retry_strategy)
session.mount("https://", adapter)
# 2. 发起请求(调整超时时间:连接10s + 读取120s)
try:
response = session.post(
"https://www.dmxapi.cn/llm-endpoint", # 替换为实际LLM接口
json={"prompt": "你的输入"},
timeout=(10, 120) # (连接超时, 读取超时)
)
response.raise_for_status() # 抛出HTTP错误
print(response.json())
except requests.exceptions.ReadTimeout:
print("仍超时,请检查网络或联系服务商")
except requests.exceptions.RequestException as e:
print(f"请求失败:{e}")
4. 预防措施
urllib3.Retry或框架自带重试)。 curl -v https://www.dmxapi.cn测试网络连通性;用ping/traceroute排查链路延迟。