From 0b193b855391724f469a503cd2b874b4d5664559 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sat, 4 May 2024 19:25:04 -0700 Subject: [PATCH] Downloader: handle one more retry case after 5770e06c4875797fc144a135a082c754cab7a92a --- download-model.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/download-model.py b/download-model.py index c38e79fb70..1681509fbb 100644 --- a/download-model.py +++ b/download-model.py @@ -190,17 +190,17 @@ def get_single_file(self, url, output_folder, start_from_scratch=False): headers = {} mode = 'wb' - if output_path.exists() and not start_from_scratch: - # Resume download - r = session.get(url, stream=True, timeout=20) - total_size = int(r.headers.get('content-length', 0)) - if output_path.stat().st_size >= total_size: - return + try: + if output_path.exists() and not start_from_scratch: + # Resume download + r = session.get(url, stream=True, timeout=20) + total_size = int(r.headers.get('content-length', 0)) + if output_path.stat().st_size >= total_size: + return - headers = {'Range': f'bytes={output_path.stat().st_size}-'} - mode = 'ab' + headers = {'Range': f'bytes={output_path.stat().st_size}-'} + mode = 'ab' - try: with session.get(url, stream=True, headers=headers, timeout=30) as r: r.raise_for_status() # If status is not 2xx, raise an error total_size = int(r.headers.get('content-length', 0))