File tree Expand file tree Collapse file tree
pycode/memilio-epidata/memilio/epidata Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ):
You can’t perform that action at this time.
0 commit comments