Python进度条和上传

时间:2015-04-10 21:20:46

标签: python upload

我使用urllib2.Request通过poster上传文件。

无论如何使用progressbar库进行上传?

import urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
# from progressbar import ProgressBar

register_openers()
datagen, headers = multipart_encode({"file": open(upfile, "rb")}) #has content-length
#progress = ProgressBar()
#for i in progress(range(80)):
#   time.sleep(0.01)
request = urllib2.Request(url, datagen, headers)
# File uploaded, get completed page
urllib2.urlopen(request).read()

1 个答案:

答案 0 :(得分:0)

使用urllib2包

Here is an example流数据。您可以在循环内添加进度递增。