1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-07-07 11:42:38 +02:00

Proper handle HTTP redirects in get_json()

This is necessary to preserve the GET parameters across redirects.
Additionally, it is nice to have a log output if a redirect occurs.
This commit is contained in:
André Koch-Kramer 2018-03-19 21:05:13 +01:00
parent 706b4cf3e6
commit 2b9ed927c7

View File

@ -774,7 +774,15 @@ class Instaloader:
sess = session if session else self.session
try:
self._sleep()
resp = sess.get('https://www.instagram.com/' + url, params=params)
resp = sess.get('https://www.instagram.com/' + url, params=params, allow_redirects=False)
while resp.is_redirect:
redirect_url = resp.headers['location']
self._log('\nHTTP redirect from {} to {}'.format('https://www.instagram.com/' + url, redirect_url))
if redirect_url.index('https://www.instagram.com/') == 0:
resp = sess.get(redirect_url if redirect_url.endswith('/') else redirect_url + '/',
params=params, allow_redirects=False)
else:
break
if resp.status_code == 404:
raise QueryReturnedNotFoundException("404")
if resp.status_code == 429: