handle https broken redirectors like ow.ly or u.afp.com

This commit is contained in:
cquest 2023-01-04 08:10:59 +01:00
parent 1b68e9e6b4
commit 92c3992708

View File

@ -24,7 +24,11 @@ def unredir(redir):
redir = redir.replace('https://ow.ly/', 'http://ow.ly/') # only http
redir = requests.get(redir, allow_redirects=False).headers.get('Location')
print('redir+', redir)
r = requests.get(redir, allow_redirects=False)
try:
r = requests.get(redir, allow_redirects=False, timeout=5)
except:
redir = redir.replace('https://', 'http://') # only http ?
r = requests.get(redir, allow_redirects=False)
return redir