检查代理是否可用 Args: test_url: 测试 URL Returns: bool: 代理是否可用
(self, test_url: str = "https://httpbin.org/ip")
| 197 | raise HTTPClientError(f"下载文件失败: {url} - {e}") |
| 198 | |
| 199 | def check_proxy(self, test_url: str = "https://httpbin.org/ip") -> bool: |
| 200 | """ |
| 201 | 检查代理是否可用 |
| 202 | |
| 203 | Args: |
| 204 | test_url: 测试 URL |
| 205 | |
| 206 | Returns: |
| 207 | bool: 代理是否可用 |
| 208 | """ |
| 209 | if not self.proxy_url: |
| 210 | return False |
| 211 | |
| 212 | try: |
| 213 | response = self.get(test_url, timeout=10) |
| 214 | return response.status_code == 200 |
| 215 | except Exception: |
| 216 | return False |
| 217 | |
| 218 | def close(self): |
| 219 | """关闭会话""" |