From 20819d2597533b378023b4f22e6a6cce4ce60940 Mon Sep 17 00:00:00 2001 From: corpone <54426320+corpone@users.noreply.github.com> Date: Thu, 22 Aug 2019 19:53:52 -0700 Subject: [PATCH] handle alternate rate limit exceeded behavior of redirecting to login --- instaloader/instaloadercontext.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/instaloader/instaloadercontext.py b/instaloader/instaloadercontext.py index 330d65c..b8eec58 100644 --- a/instaloader/instaloadercontext.py +++ b/instaloader/instaloadercontext.py @@ -358,6 +358,9 @@ class InstaloaderContext: while resp.is_redirect: 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'): + # alternate rate limit exceeded behavior + raise TooManyRequestsException("429 Too Many Requests: 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)