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