我使用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()