instaloader: Login error
Hi,
I got error KeyError: "name='csrftoken', domain=None, path=None", when trying to login
instaloder ver : 4.9.5
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 28
- Comments: 45 (1 by maintainers)
Thanks @IL2C! I have tested your code and can confirm logging in does not produce an error anymore. So for those of you who cannot wait to use Instaloader again:
(Of course you should always double-check when you’re installing code from someone else’s repository. But at the time of posting the repo was exactly 1 commit ahead of the Instaloader main repo, with only the headers changed.)
This is how I fixed it:
HOW TO FIX
KeyError: "name='csrftoken', domain=None, path=None"BUG (assuming you have Instaloader already installed)STEP 1:
Follow these steps: (based on: https://instaloader.github.io/troubleshooting.html#login-error )
A. Download the script: Example 615_import_firefox_session.py https://raw.githubusercontent.com/instaloader/instaloader/master/docs/codesnippets/615_import_firefox_session.py B. Open Firefox and go to the “Privacy & Security” settings (about:preferences#privacy) C. Change “History”-Settings from “Use custom settings for history” -> “Always use custom browsing mode” to “Remember history”.
STEP 2:
A. Open CMD as administrator and go to wherever you downloaded the script to B. Execute
python 615_import_firefox_session.pySTEP 3:
Problem solved, now execute any Instaloader command using the “–login=usernameFromSession” argument
@evanmiltenburg thanks, it works!
Fixed in v4.10.1 thanks to #2088.
Replacing the default user agent with any from this list resolves this issue. https://github.com/instaloader/instaloader/blob/ffb0aea5eb79b58ebad1eee57ad097bc2aba0689/instaloader/instaloadercontext.py#L34
From what I’ve gathered, using a user agent that doesn’t correlate Instagram software won’t access the csrftoken cookie when sending the post request to login. https://github.com/instaloader/instaloader/blob/3cc29a4ceb3ff4cd04a73dd4b20979b03128f454/instaloader/instaloadercontext.py#L222
Upading the user agent worked for me.
Quick guide on how to do that without relying on an external fork:
instaloader/instaloader/instaloadercontext.pyin a text editordefault_user_agent, currently it’s on line 34return 'insert the user agent you chose'pip install ./instaloader, your existing installation should get uninstalled, your local edited one should get installedpip install instaloaderI am preparing a file, to upload (which will be an explanation of the problems we are having, and why. But it is an unfinished version. Although enough to explain, certain things. The reason for not finishing it quickly, is that my English It is very bad, and use the Google Translate a lot, which is not very good either. And as I am Spanish, well …
Greetings.
I think I have a workaround:
Now Instagram kicks me out even though I use @evanmiltenburg’s work-around. Anyone else?
The only thing the code does is changes the default user agent. You can override the user agent more easily with a command line parameter. In any case, I still get instant ban when I try to login using this code and/or the specified user agent.
Hello, Working for me with parameter : --user-agent And user agent in this list : https://developers.whatismybrowser.com/useragents/explore/software_name/instagram/ Mathieu
Hello,
I have the same problem with 4.9.5 (windows standalone).
Do you have a solution for this binary version ?
Thanks, Mathieu
Works for me with no issues. Thanks!
Many thanks for workarounds or corrections, I’ll try them and keep in touch ! Thanks for all this work !
Vincent,
Envoyé de mon SmartPhone .
Not working for me on MacOS. I can see the “csrftoken” in the sql file, but after running the script, the error shows up again.
I’ve also tried to do the login directly after the “instaloader.save_session_to_file(sessionfile)” in the script -> no difference, same error.
Trying to follow this method I even get the following error:
I am currently logged into Instagram. Not sure what else to do? Wasn’t there a browser plugin that could download Sessions/Cookies?
Edit: Only works in non-private mode. Had it enabled by default.
Edit 2: After importing the session it begins working.