(self)
| 377 | self.log(f"🚫 重试{max_retries}次均失败,回退至本地IP") |
| 378 | |
| 379 | def failover_proxy(self): |
| 380 | proxy_api = os.environ.get("UNICOM_PROXY_API") |
| 381 | if not proxy_api: |
| 382 | return False |
| 383 | self.log("⚠️ [故障转移] 检测到网络不稳定,正在检查当前代理是否存活...") |
| 384 | try: |
| 385 | requests.get("https://www.baidu.com", proxies=self.session.proxies, timeout=3) |
| 386 | self.log("✅ [故障转移] 经测试当前IP仍有效,继续复用,暂不提取新IP。") |
| 387 | time.sleep(1) |
| 388 | return True |
| 389 | except Exception as e: |
| 390 | self.log(f"❌ [故障转移] 当前代理已失效 ({e}),准备更换新IP...") |
| 391 | time.sleep(2) |
| 392 | self.configure_proxy() |
| 393 | return True |
| 394 | |
| 395 | def init_account(self, config_str): |
| 396 | parts = config_str.split('#') |
no test coverage detected