【发布时间】:2014-05-18 14:54:44
【问题描述】:
我正在使用 python 2.7 requests 模块使用以下代码下载二进制文件,如何使此代码“自动恢复”部分下载文件的下载。
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 模块来实现这一点。
【问题讨论】:
标签: python python-2.7 python-requests