mirror of
https://github.com/cquest/tootbot.git
synced 2024-11-23 20:11: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
|
||||
if redir_count > 10:
|
||||
break
|
||||
if 'http' not in r.headers.get('Location'):
|
||||
redir = re.sub(r'(https?://.*)/.*', r'\1', redir) + \
|
||||
r.headers.get('Location')
|
||||
location = r.headers.get('Location')
|
||||
if 'http' not in location:
|
||||
redir = re.sub(r'(https?://[^/]*).*$', r'\1', redir) + location
|
||||
else:
|
||||
redir = r.headers.get('Location')
|
||||
# print('redir', redir)
|
||||
redir = location
|
||||
if '//ow.ly/' in redir or '//bit.ly/' in 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)
|
||||
try:
|
||||
r = requests.get(redir, allow_redirects=False, timeout=5)
|
||||
except:
|
||||
|
|
Loading…
Reference in New Issue
Block a user