1def download_file(url):
2 local_filename = url.split('/')[-1]
3 # NOTE the stream=True parameter below
4 with requests.get(url, stream=True) as r:
5 r.raise_for_status()
6 with open(local_filename, 'wb') as f:
7 for chunk in r.iter_content(chunk_size=8192):
8 # If you have chunk encoded response uncomment if
9 # and set chunk_size parameter to None.
10 #if chunk:
11 f.write(chunk)
12 return local_filename