1import requests
2
3def download_file(url):
4 local_filename = url.split('/')[-1]
5 # NOTE the stream=True parameter
6 r = requests.get(url, stream=True)
7 with open(local_filename, 'wb') as f:
8 for chunk in r.iter_content(chunk_size=1024):
9 if chunk: # filter out keep-alive new chunks
10 f.write(chunk)
11 #f.flush() commented by recommendation from J.F.Sebastian
12 return local_filename
13
14download_file("http://www.jpopsuki.tv/images/media/eec457785fba1b9bb35481f438cf35a7_1351466328.mp4")
15