我正在使用python 2.7请求模块使用以下代码下载二进制文件,如何使此代码从部分下载的文件中“自动恢复”下载。
r = requests.get(self.fileurl, stream=True, verify=False, allow_redirects=True)
if r.status_code == 200:
CHUNK_SIZE = 8192
bytes_read = 0
with open(FileSave, 'wb') as f:
itrcount=1
for chunk in r.iter_content(CHUNK_SIZE):
itrcount=itrcount+1
f.write(chunk)
bytes_read += len(chunk)
total_per = 100 * float(bytes_read)/float(long(audioSize)+long(videoSize))
self.progress_updates.emit('%d\n%s' % (total_per, 'Download Progress : ' + self.size_human(itrcount*CHUNK_SIZE) + '/' + Total_Size))
r.close()
我更愿意只使用 requests
如果可能的话,实现这个目标