Created
August 3, 2020 06:39
-
-
Save NanoDano/d4f8fdf8e1a7e90166b5c781d0bf0148 to your computer and use it in GitHub Desktop.
Download a file with Python requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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