insta_share icon indicating copy to clipboard operation
insta_share copied to clipboard

Login problem fix

Open oluca opened this issue 4 years ago • 1 comments

Hey guys,

i have the problem that i cant login through login() and following code fixed it for me:


def login(self, username: str, password: str) -> dict:
        url = 'https://www.instagram.com/data/shared_data/'
        login_url = 'https://www.instagram.com/accounts/login/ajax/'

        time = int(datetime.now().timestamp())

        session = requests.Session()
        response = session.get(url)
        csrf = json.loads(response.text)['config']['csrf_token']

oluca avatar Jan 18 '22 19:01 oluca

There is no 'csrf_token' now in response, because instagram change login page and 'csrf_token' is generated dynamically in JavaScript 'window._sharedData'. So to get this token you can use Selenium

Dymirt avatar Oct 08 '22 09:10 Dymirt