Skip to content

Instantly share code, notes, and snippets.

@robsmith1776
Created October 21, 2016 21:31
Show Gist options
  • Save robsmith1776/51d70820d5b425533fa20f842a0a2c17 to your computer and use it in GitHub Desktop.
Save robsmith1776/51d70820d5b425533fa20f842a0a2c17 to your computer and use it in GitHub Desktop.
download_python_requests.py
def download_file(url):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
#f.flush() commented by recommendation from J.F.Sebastian
return local_filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment