httplib's HEAD request, and https protocol

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


Ok, nevermind. Appereantly there is such a thing as HTTPSConnection. I
thought httplib auto-handled https connections..

22 Eylül 2011 13:43 tarihinde Yaşar Arabacı <yasar11732 at gmail.com> yazdı:

> 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/
>
>


-- 
http://yasar.serveblog.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110922/6abbea11/attachment.html>


More information about the Python-list mailing list