httplib2 download progress bar in python

697 views Asked by At

Is it possible to display the percentage a file has downloaded in python while using httplib2? I know you can with urllib2 but I want to use httplib2.

2

There are 2 answers

1
Amber On BEST ANSWER

No. httplib2 doesn't have any kind of progress beacon callback, so it simply blocks until the request is finished.

0
fffonion On

i'm not very sure with how to use async() seems it's already OFFICIALLY solved.

and it's possible to modify httplib2 by your self: (add a callback function arg to the request() func) in class Http: in def _request: modify it to:

def _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey,callback=None):

in def _conn_requst: modify it to:

def _conn_request(self, conn, request_uri, method, body, headers,callback=None):

modify this below

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

when use you can type like this:

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

the first 8192 is chunk size, and callbackfunc is the callback function you defined(like in urllib)