From 803440ac501d929367ffb88d0bc6acec17316652 Mon Sep 17 00:00:00 2001 From: twitter-79 <42436876+twitter-79@users.noreply.github.com> Date: Wed, 16 Jun 2021 22:35:58 +0200 Subject: [PATCH] Fix Login Error (#1192) taking csrf token from login page as it is empty using the old url Fixes #1150. --- instaloader/instaloadercontext.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instaloader/instaloadercontext.py b/instaloader/instaloadercontext.py index 8234e96..66b245c 100644 --- a/instaloader/instaloadercontext.py +++ b/instaloader/instaloadercontext.py @@ -210,8 +210,8 @@ class InstaloaderContext: # Override default timeout behavior. # Need to silence mypy bug for this. See: https://github.com/python/mypy/issues/2427 session.request = partial(session.request, timeout=self.request_timeout) # type: ignore - session.get('https://www.instagram.com/web/__mid/') - csrf_token = session.cookies.get_dict()['csrftoken'] + csrf_json = self.get_json('accounts/login/', {}, session=session) + csrf_token = csrf_json['config']['csrf_token'] session.headers.update({'X-CSRFToken': csrf_token}) # Not using self.get_json() here, because we need to access csrftoken cookie self.do_sleep()