Skip to content

Instantly share code, notes, and snippets.

@clpo13
Last active April 20, 2019 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clpo13/93c5f5e63e0f97161aad4621e1586e66 to your computer and use it in GitHub Desktop.
Save clpo13/93c5f5e63e0f97161aad4621e1586e66 to your computer and use it in GitHub Desktop.
321,323c321,326
< # Perform a HEAD request to obtain the Content-Length
< r = requests.head(location)
< content_length = int(r.headers.get('content-length', 0))
---
> # Perform a request to obtain the Content-Length header
> r = requests.get(location, stream=True)
> try:
> content_length = int(r.headers['content-length'])
> except KeyError:
> content_length = len(r.content)
326c329
< return requests.get(location, stream=True)
---
> return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment