fix endless loop redirects

This commit is contained in:
cquest 2023-06-02 11:56:38 +02:00
parent dfde209171
commit 5b562ff379

View File

@ -22,16 +22,14 @@ def unredir(redir):
redir_count = redir_count + 1 redir_count = redir_count + 1
if redir_count > 10: if redir_count > 10:
break break
if 'http' not in r.headers.get('Location'): location = r.headers.get('Location')
redir = re.sub(r'(https?://.*)/.*', r'\1', redir) + \ if 'http' not in location:
r.headers.get('Location') redir = re.sub(r'(https?://[^/]*).*$', r'\1', redir) + location
else: else:
redir = r.headers.get('Location') redir = location
# print('redir', redir)
if '//ow.ly/' in redir or '//bit.ly/' in redir: if '//ow.ly/' in redir or '//bit.ly/' in redir:
redir = redir.replace('https://ow.ly/', 'http://ow.ly/') # only http redir = redir.replace('https://ow.ly/', 'http://ow.ly/') # only http
redir = requests.get(redir, allow_redirects=False).headers.get('Location') redir = requests.get(redir, allow_redirects=False).headers.get('Location')
# print('redir+', redir)
try: try:
r = requests.get(redir, allow_redirects=False, timeout=5) r = requests.get(redir, allow_redirects=False, timeout=5)
except: except: