Authentication Error issue while login()
rohith2506 opened this issue · comments
Hey,
Once again, Sorry to bother you.
I am looking into login()
method and it throws me authentication error every time I try to login.
This is the piece of code I have tried.
from pygram import Pygram
pygr = PyGram('onebyzero2506', 'demo1234')
I did some debugging myself and it seems like the request is failing with status code 400. Did something change from instagram side (or) am I making some rookie mistake? :)
Hi @rohith2506,
I can reproduce this error. For the meanwhile you can login in a browser and manually extract the csrftoken
, dumping it to the pygram-cache.json
file in the same directory as your script with the following content:
{"user": "onebyzero2506", "headers": {"x-csrftoken": "CSRF_TOKEN", "cookie": "csrftoken=CSRF_TOKEN"}}
It seems the parameter password
is no longer supported and the password has to be sent encrypted through the field enc_password
to avoid the 400 error. Is not trivial to fix this. I think the encryption code for the password is here: https://www.instagram.com/static/bundles/es6/PasswordEncryptionLogger.js/6fb978a9712f.js.
Actually, you don't need the proper encryption for now. You can get away with it using this.
pgrimaud/instagram-user-feed@96ad4cf
Using Plaintext mode, you can just send the password in plaintext.
You might have to modify the logic to using requests session. This is needed for session id. I tried and tested this in both golang and python. This works.
For python reference, you can take a look into this piece of code
https://github.com/instaloader/instaloader/blob/master/instaloader/instaloadercontext.py#L192
Great finding @rohith2506, thank you! I'll try that later.
@rohith2506, I was testing that but it won't login properly. Haven't you got any trouble with the challenge URLs? I tried from different accounts and confirmed the "suspicious" activity in the browser but I don't receive the sessionid
. At least the password works like that.