httplib's HEAD request, and https protocol

Yaşar Arabacı yasar11732 at gmail.com
Thu Sep 22 12:43:48 CEST 2011


Hi,

I wrote a function to get thorugh redirections and find a final page for a
given web-page. But following function gives maximum recursion error for any
https pages I tried. Do you know what might be the problem here?

def getHeadResponse(url,response_cache = {}):
    try:
        return response_cache[url]
    except KeyError:
        url = urlparse.urlparse(url)
        conn = httplib.HTTPConnection(url.netloc)
        try:
            conn.request("HEAD",url.path)
        except:
            # Anything can happen, this is SPARTA!
            return None
        response = conn.getresponse()
        response_cache[url.geturl()] = response
        return response

def getFinalUrl(url):
    "Navigates through redirections to get final url."

    response = getHeadResponse(url)
    try:
        if str(response.status).startswith("3"):
            return getFinalUrl(response.getheader("location"))
    except AttributeError:
        pass
    return url
-- 
http://yasar.serveblog.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110922/39f1d94b/attachment.html>


More information about the Python-list mailing list