Skip to content

Instantly share code, notes, and snippets.

@NanoDano
Created August 3, 2020 06:39
Show Gist options
  • Save NanoDano/d4f8fdf8e1a7e90166b5c781d0bf0148 to your computer and use it in GitHub Desktop.
Save NanoDano/d4f8fdf8e1a7e90166b5c781d0bf0148 to your computer and use it in GitHub Desktop.
Download a file with Python requests
import requests # pip install requests
# Adapted from answer at: https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests
def download(url, filepath):
with requests.get(url, stream=True) as response:
response.raise_for_status()
with open(filepath, 'wb') as output_file:
for chunk in response.iter_content(chunk_size=8192):
# If you have chunk encoded response, then uncomment
# the `if` statement and set chunk_size parameter to `None`.
# if chunk:
output_file.write(chunk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment