, HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Max retries exceeded with...

2025年11月12日 16:14 processing

错误信息

Run failed: [models] Server Unavailable Error, HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7fdcaaedc0b0>, 'Connection to www.dmxapi.cn timed out. (connect timeout=10)'))

AI 解决方案

错误翻译


原文:HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7fdcaaedc0b0>, 'Connection to www.dmxapi.cn timed out. (connect timeout=10)'))
译文:HTTPS连接池(主机='www.dmxapi.cn', 端口=443): 达到最大重试次数,URL: /v1/chat/completions (原因为连接超时错误,连接到www.dmxapi.cn超时(连接超时时间为10秒))

原因分析


网络连接超时:尝试连接DMXAPI服务器(www.dmxapi.cn)时,在10秒内未能建立连接,达到最大重试次数后失败。

解决方案


# 方案1:增加超时时间
import requests
import urllib3

# 增加连接超时时间(例如设为30秒)
response = requests.post(
    'https://www.dmxapi.cn/v1/chat/completions',
    timeout=(10, 30)  # 连接超时10秒,读取超时30秒
)

# 方案2:添加重试机制
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry

session = requests.Session()
retry_strategy = Retry(
    total=3,
    backoff_factor=1,
    status_forcelist=[429, 500, 502, 503, 504],
)
adapter = HTTPAdapter(max_retries=retry_strategy)
session.mount("http://", adapter)
session.mount("https://", adapter)

response = session.post('https://www.dmxapi.cn/v1/chat/completions', timeout=30)

️ 预防措施


  • 网络检查:在请求前先检查网络连接状态,确保网络畅通

  • 异常处理:添加完善的异常处理机制,包括连接超时、请求超时等情况的处理

  • 服务监控:定期检查API服务状态,确保服务可用性
  • 推荐工具

  • 使用ping www.dmxapi.cn检查网络连通性

  • 使用Postman等工具测试API接口可用性