Skip to content

Commit 7d46233

Browse files
authored
1079 Handle Chunked-Encoding Downloads (#1080)
1 parent a97183a commit 7d46233

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

pycode/memilio-epidata/memilio/epidata/getDataIntoPandasDataFrame.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,19 @@ def download_file(
202202
"Error: URL " + url + " could not be opened.")
203203
if req.status_code != 200: # e.g. 404
204204
raise requests.exceptions.HTTPError("HTTPError: "+str(req.status_code))
205-
# get file size from http header
206-
# this is only the number of bytes downloaded, the size of the actual file
207-
# may be larger (e.g. when 'content-encoding' is gzip; decoding is handled
208-
# by iter_content)
209-
file_size = int(req.headers.get('content-length'))
205+
if ('content-length' in req.headers) and progress_function:
206+
# get file size from http header
207+
# this is only the number of bytes downloaded, the size of the actual file
208+
# may be larger (e.g. when 'content-encoding' is gzip; decoding is handled
209+
# by iter_content)
210+
# this is only needed for the progress indicator
211+
file_size = int(req.headers.get('content-length'))
212+
# if content length is not known, a progress cant be set.
213+
set_progr = True
214+
else:
215+
set_progr = False
210216
file = bytearray() # file to be downloaded
211-
if progress_function:
217+
if set_progr:
212218
progress = 0
213219
# download file as bytes via iter_content
214220
for chunk in req.iter_content(chunk_size=chunk_size):

0 commit comments

Comments
 (0)