1

I use requests to solve twitter urls, it works for all valid URLs, but if the URL cant be resolved, the variable r will get me the the input value as response. If I copy the URL into a browser I it wont get loaded, but the url will be resolved.

Is there a method, to resolve redirection URLs, also when the target-url can't get loaded.

def unshortenTwitterURL(url):
  try:
    r = requests.head(url, allow_redirects=True, timeout=10)
    res = r.url
  except:
    res = url
  return res

1 Answer 1

2

Do not allow redirects. And then look at r.headers['location'].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.