From bc40d334b9ba8844a9a34761069d51dc023baf0a Mon Sep 17 00:00:00 2001 From: yml2213 Date: Mon, 22 Jun 2026 20:32:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20requests=202.34+=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=20ProxyError=20=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - requests 2.34+ 已移除 ProxyError 属性 - 代理错误统一为 ConnectionError,通过错误信息判断是否为代理问题 - 代理错误时刷新代理并重试,非代理连接错误也重试 Co-Authored-By: Claude Fable 5 --- core/douyu/login.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/core/douyu/login.py b/core/douyu/login.py index 68ed527..8453e6e 100644 --- a/core/douyu/login.py +++ b/core/douyu/login.py @@ -162,16 +162,27 @@ class DouyuLogin: f"{method.upper()} {safe_url} 超时,耗时 {elapsed:.1f}s," f"timeout={timeout}" ) from exc - except requests.ProxyError as exc: + except requests.ConnectionError as exc: + # requests 2.34+ 已移除 ProxyError,代理错误统一为 ConnectionError + is_proxy_err = "proxy" in str(exc).lower() or "Proxy" in type(exc).__name__ + if is_proxy_err: + elapsed = time.monotonic() - started + logger.warning(f"代理连接失败,尝试 {attempt + 1}/{max_retries}: {exc}") + if attempt < max_retries - 1: + self._refresh_proxy() + time.sleep(1) + continue + raise ConnectionError( + f"{method.upper()} {safe_url} 代理连接失败,已重试 {max_retries} 次" + ) from exc + # 非代理的 ConnectionError 也重试 elapsed = time.monotonic() - started - logger.warning(f"代理连接失败,尝试 {attempt + 1}/{max_retries}: {exc}") + logger.warning(f"连接失败,尝试 {attempt + 1}/{max_retries}: {exc}") if attempt < max_retries - 1: - # 刷新代理 - self._refresh_proxy() time.sleep(1) continue raise ConnectionError( - f"{method.upper()} {safe_url} 代理连接失败,已重试 {max_retries} 次" + f"{method.upper()} {safe_url} 连接失败,已重试 {max_retries} 次" ) from exc except requests.RequestException as exc: elapsed = time.monotonic() - started