(url, filename)
| 7 | |
| 8 | |
| 9 | def download(url, filename): |
| 10 | try: |
| 11 | with requests.get(url, stream=True, timeout=10) as response: |
| 12 | response.raise_for_status() # Raises error for 4xx/5xx |
| 13 | |
| 14 | with open(filename, "wb") as file: |
| 15 | for chunk in response.iter_content(chunk_size=8192): |
| 16 | if chunk: |
| 17 | file.write(chunk) |
| 18 | |
| 19 | print(f"Successfully downloaded: {filename}") |
| 20 | |
| 21 | except requests.exceptions.RequestException as e: |
| 22 | print(f"Download failed: {e}") |
| 23 | |
| 24 | |
| 25 | # Example usage |