python中的httplib2下载进度条

python中的httplib2下载进度条,python,progress-bar,httplib2,Python,Progress Bar,Httplib2,在使用httplib2时,是否可以显示文件在python中下载的百分比?我知道可以使用urllib2,但我想使用httplib2。否。httplib2没有任何类型的进度信标回调,因此它只是阻塞,直到请求完成。我不太确定如何使用async() 看来已经正式解决了 您可以自己修改httplib2: (将回调函数arg添加到request()func) 类内Http: 在def\U请求中:将其修改为: def _request(self, conn, host, absolute_uri, reque

在使用httplib2时,是否可以显示文件在python中下载的百分比?我知道可以使用urllib2,但我想使用httplib2。

否。
httplib2
没有任何类型的进度信标回调,因此它只是阻塞,直到请求完成。

我不太确定如何使用async() 看来已经正式解决了

您可以自己修改httplib2: (将回调函数arg添加到request()func) 类内Http: 在def\U请求中:将其修改为:

def _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey,callback=None):
def _conn_request(self, conn, request_uri, method, body, headers,callback=None):
在def连接要求中:将其修改为:

def _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey,callback=None):
def _conn_request(self, conn, request_uri, method, body, headers,callback=None):
修改如下

if method == "HEAD":
    conn.close()
else:
    if not callback:
        content = response.read()
    else:
        while 1:
           content=response.read(callback[0])
           if not content:break
           callback[1]()
使用时,您可以这样键入:

resp, content = h.request("http://stackoverflow.com", [8192,callbackfunc])

前8192是chunk size,callbackfunc是您定义的回调函数(如在urllib中)

这里有一个关于它的错误报告