while True: try: print(path) with open(path, 'wb') as download_file: url = fil.url with httpx.stream("GET", url, follow_redirects=True) as response: total = int(response.headers["Content-Length"]) with rich.progress.Progress( "[progress.percentage]{task.percentage:>3.0f}%", rich.progress.BarColumn(bar_width=None), rich.progress.DownloadColumn(), rich.progress.TransferSpeedColumn(), ) as progress: download_task = progress.add_task("Download", total=total) for chunk in response.iter_bytes(): download_file.write(chunk) progress.update(download_task, completed=response.num_bytes_downloaded) except Exception as e: print(f"Error: {e}. Retrying.") time.sleep(5) continue except BaseException: os.unlink(path) raise break