LLM call failed: HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Read timed...

2026年04月22日 18:48 processing

错误信息

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秒内未收到服务器响应数据,触发读取超时。

  • 发生位置:LLM调用时的网络请求环节(向dmxapi.cn发送HTTPS请求)。
  • 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. 预防措施


  • 最佳实践1:根据网络环境合理设置超时(如连接超时5-10s、读取超时60-180s),避免过短或过长。

  • 最佳实践2:对 transient 错误(超时、5xx状态码)实现有限重试(用urllib3.Retry或框架自带重试)。

  • 推荐工具:用curl -v https://www.dmxapi.cn测试网络连通性;用ping/traceroute排查链路延迟。