简体   繁体   English

Python进度条和上传

[英]Python progress bar and uploads

I'm uploading files through poster using urllib2.Request. 我正在使用urllib2.Request通过海报上传文件。

Is there anyway to use the progressbar library with uploading? 无论如何,在上传时使用进度条库吗?

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()

Here is an example of streaming data using the urllib2 package. 这是使用urllib2包流式传输数据的示例 You would add your progress incrementing inside the loop. 您将在循环内增加进度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM