From 0be11291739e0f62c34a024b249fab109ac7a81b Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Fri, 4 Dec 2020 13:12:24 +0100 Subject: [PATCH] Fix login redirect triggering 429 handling Closes #902. --- instaloader/instaloadercontext.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/instaloader/instaloadercontext.py b/instaloader/instaloadercontext.py index a138092..51e83f3 100644 --- a/instaloader/instaloadercontext.py +++ b/instaloader/instaloadercontext.py @@ -324,8 +324,10 @@ class InstaloaderContext: redirect_url = resp.headers['location'] self.log('\nHTTP redirect from https://{0}/{1} to {2}'.format(host, path, redirect_url)) if redirect_url.startswith('https://www.instagram.com/accounts/login'): + if not self.is_logged_in: + raise LoginRequiredException("Redirected to login page. Use --login.") # alternate rate limit exceeded behavior - raise TooManyRequestsException("429 Too Many Requests: redirected to login") + raise TooManyRequestsException("Redirected to login") if redirect_url.startswith('https://{}/'.format(host)): resp = sess.get(redirect_url if redirect_url.endswith('/') else redirect_url + '/', params=params, allow_redirects=False)