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://mail.python.org/mailman/listinfo/python-list