mirror of
https://github.com/cquest/tootbot.git
synced 2024-11-24 04:21:06 +00:00
fix endless loop redirects
This commit is contained in:
parent
dfde209171
commit
5b562ff379
10
tootbot.py
10
tootbot.py
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user