下载文件 Args: url: 文件 URL filepath: 保存路径 chunk_size: 块大小 Raises: HTTPClientError: 下载失败
(self, url: str, filepath: str, chunk_size: int = 8192)
| 173 | return self.request("PATCH", url, data=data, json=json, **kwargs) |
| 174 | |
| 175 | def download_file(self, url: str, filepath: str, chunk_size: int = 8192) -> None: |
| 176 | """ |
| 177 | 下载文件 |
| 178 | |
| 179 | Args: |
| 180 | url: 文件 URL |
| 181 | filepath: 保存路径 |
| 182 | chunk_size: 块大小 |
| 183 | |
| 184 | Raises: |
| 185 | HTTPClientError: 下载失败 |
| 186 | """ |
| 187 | try: |
| 188 | response = self.get(url, stream=True) |
| 189 | response.raise_for_status() |
| 190 | |
| 191 | with open(filepath, 'wb') as f: |
| 192 | for chunk in response.iter_content(chunk_size=chunk_size): |
| 193 | if chunk: |
| 194 | f.write(chunk) |
| 195 | |
| 196 | except Exception as e: |
| 197 | raise HTTPClientError(f"下载文件失败: {url} - {e}") |
| 198 | |
| 199 | def check_proxy(self, test_url: str = "https://httpbin.org/ip") -> bool: |
| 200 | """ |
nothing calls this directly
no test coverage detected