] hy4-preview user_info attempt=2 HTTPSConnectionPool(host='www.dmxapi.cn', port...
错误信息
[API_ERROR] hy4-preview user_info attempt=2 HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Read timed out. (read timeout=300)
[FAILED] hy4-preview input=6 HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Read timed out. (read timeout=300)
AI 解决方案
原文:[API_ERROR] hy4-preview user_info attempt=2 HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Read timed out. (read timeout=300)
[FAILED] hy4-preview input=6 HTTPSConnectionPool(host='www.dmxapi.cn', port=443): Read timed out. (read timeout=300)
译文:[API_ERROR] hy4-preview 用户信息 第2次尝试 HTTPS连接池(主机='www.dmxapi.cn', 端口=443): 读取超时。(读取超时=300秒)
[失败] hy4-preview 输入=6 HTTPS连接池(主机='www.dmxapi.cn', 端口=443): 读取超时。(读取超时=300秒)
🎯 原因分析
www.dmxapi.cn 发起HTTPS请求时,超过300秒未收到服务器响应,导致连接池读取超时。www.dmxapi.cn 的端口443时触发,涉及请求为user_info和input=6。💡 解决方案
# 修复后的代码
from requests.adapters import HTTPAdapter
from requests import Session
def create_retry_session(timeout=600):
session = Session()
# 增加超时时间到600秒,并配置自动重试
session.mount('https://', HTTPAdapter(max_retries=3))
return session
session = create_retry_session(timeout=600)
response = session.get('https://www.dmxapi.cn/api/user_info', timeout=timeout)
🛡️ 预防措施
urllib3.Retry 或 HTTPAdapter 实现重试逻辑,提升服务稳定性。