Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top