Skip to content

Commit

Permalink
Downloader: handle one more retry case after 5770e06
Browse files Browse the repository at this point in the history
  • Loading branch information
oobabooga committed May 5, 2024
1 parent cb31998 commit 0b193b8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions download-model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 0b193b8

Please sign in to comment.