From 5d156c6a1510aab8d64daf709517691dd065cfb5 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Sun, 3 Apr 2022 02:34:30 +0000 Subject: [PATCH] Detect and raise error on redirect from GraphQL endpoint to login #165 --- snscrape/modules/instagram.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/snscrape/modules/instagram.py b/snscrape/modules/instagram.py index 4a89f3d..14483e0 100644 --- a/snscrape/modules/instagram.py +++ b/snscrape/modules/instagram.py @@ -96,6 +96,8 @@ class _InstagramCommonScraper(snscrape.base.Scraper): def _check_json_callback(self, r): if r.status_code != 200: return False, f'status code {r.status_code}' + if r.url.startswith('https://www.instagram.com/accounts/login/'): + raise snscrape.base.ScraperException('Redirected to login page') try: obj = json.loads(r.text) except json.JSONDecodeError as e: