I've been searching (without results) a reanudable (i don't know if this is the correct word, sorry) way to download big files from internet with python, i know how do it directly with urllib2, but if something interrupt the connection, i need some way to reconnect and continue the download where it was if it's possible (like a download manager).
Asked
Active
Viewed 74 times
2
-
2Duplicate of: http://stackoverflow.com/a/1798945/276949 – Martin Konecny May 12 '15 at 04:20
-
2possible duplicate of [Download file using partial download (HTTP)](http://stackoverflow.com/questions/1798879/download-file-using-partial-download-http) – Tim McNamara May 12 '15 at 04:58
1 Answers
0
For other people who can help the answer, there's a HTTP protocol called Chunked Transfer Encoding that allow to do this specifying the 'Range' header of the request with the beginning and end bytes (separated by a dash), thus is possible just count how many bytes was downloaded previously and send it like the new beginning byte for continue the download. Example with requests module:
import requests
from os.path import getsize
#get size of previous downloaded chunk file
beg = getsize(PATH_TO_FILE)
#if we want we can get the size before download the file (without actually download it)
end = request.head(URL).headers['content-length']
#continue the download in the next byte from where it stopped
headers = {'Range': "bytes=%d-%s"%(beg+1,end)}
download = requests.get(URL, headers=headers)

Ricardo B.
- 110
- 1
- 11