Skip to content

Instantly share code, notes, and snippets.

@tylerdave
Created August 14, 2013 03:34
Show Gist options
  • Save tylerdave/6227791 to your computer and use it in GitHub Desktop.
Save tylerdave/6227791 to your computer and use it in GitHub Desktop.
resolve redirected URLs (max one redirect)
import requests
def _resolve_redirected_url(url):
response = requests.get(url, allow_redirects=False)
if response.status_code in [301, 302, 307, 308] and 'location' in response.headers:
url = response.headers['location']
return url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment