def unshorten_url(url):
    parsed = urlparse.urlparse(url)
h = httplib.HTTPConnection(parsed.netloc)
h.request('HEAD', parsed.path)
response = h.getresponse()
if response.status / 100 == 3 and response.getheader('Location'):
    return response.getheader('Location')
else:
    return url
How can I unshorten a URL?