I want to upload a file with http-url to a local file. File is large enough, and I want to download it and save it, but do not read(), and write()the whole file as one giant string.
The interface urllib.urlretrieveis what I want. However, I see no way to set request headers on boot through urllib.urlretrieve, which should I do.
If I use urllib2, I can set request headers through its object Request. However, I do not see the API in urllib2for downloading the file directly to the path on the disk, for example urlretrieve. It seems that instead I will have to use a loop to iterate over the returned data in chunks, write it to a file, and check when we are done.
What would be the best way to create a function that works like urllib.urlretrieve, but allows you to pass request headers?
sssssss
source
share