instaloader: Login error: JSON decode fail, 403 - Forbidden.
Describe the bug Today I tried to login from two different accounts, from different IPs, and received a login error, 429 forbidden.
To Reproduce
Steps to reproduce the behavior:
instaloader --login <username> profile nasa
Expected behavior I expected to login and start downloading posts.
Error messages and tracebacks
Using above command line, I receive this:
Fatal error: Login error: JSON decode fail, 403 - Forbidden.
Using module, I get:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/instaloader/instaloadercontext.py", line 224, in login
resp_json = login.json()
File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/bin/ig-login.py", line 57, in <module>
L.login(USER, PASSWORD)
File "/usr/local/lib/python3.7/dist-packages/instaloader/instaloader.py", line 546, in login
self.context.login(user, passwd)
File "/usr/local/lib/python3.7/dist-packages/instaloader/instaloadercontext.py", line 228, in login
) from err
instaloader.exceptions.ConnectionException: Login error: JSON decode fail, 403 - Forbidden.
Instaloader version 4.7.1
Additional context
If I try to login via web or via app, I don’t have any problems. My accounts seem perfectly fine. Also, without logging in, e.g.
instaloader nasa
I can download posts, so I guess my IP range is not banned.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 20
- Comments: 41 (1 by maintainers)
Commits related to this issue
- Fix Login Error (#1192) taking csrf token from login page as it is empty using the old url Fixes #1150. — committed to instaloader/instaloader by twitter-79 3 years ago
This seems to be a problem with retrieving the csrf token
in line 214 of instaloadercontext.py does not work for me while
is working fine!
I get this error in the EU, but if I set my VPN to India everything works just fine! So thanks for the tip 😃
As a workaround for those having the login problem, you can use the script described in https://instaloader.github.io/troubleshooting.html#login-error I also had the problem this morning and going this way to create the session file just works fine for me.
Thank you @Creat1veM1nd, I was looking for that. It works perfect for me
@shyland89 Not sure if that is what you need, but I got my python script working with that.
I excuted the script @Michounet did, calling it with
python <scriptname> -c <pathto>/cookies.txtWith that I got a session.Then I changed in my script
L.login("USERNAME" , "PASSWORD")to
L.load_session_from_file("USERNAME")Now my script works fine again so far.
Thanks for the work around I really appreciate it! I ran your script and it executed perfectly. I’m quite new to exploring python and was just wondering where do I update the previous script to call from your portion?
def get_instagram_posts(username, startdate, enddate): – Create an instaloader object with parameters L = instaloader.Instaloader(download_pictures = False, download_videos = False, download_comments= False, compress_json = False)
Log in with the instaloader object
–.login(“USERNAME” , “PASSWORD”)
– Search the instagram profile profile = instaloader.Profile.from_username(L.context, username) – Scrape the posts posts = profile.get_posts() for post in takewhile(lambda p: p.date > startdate, dropwhile(lambda p : p.date > enddate, posts)): print(post.date) L.download_post(post, target = profile.username)
import os from datetime import datetime – instagram username username = ‘USERNAME’ – daterange of scraping startdate = datetime(2021, 1, 1) enddate = datetime(2021, 6, 1) – get your current working directory – current_wkdir = os.get_cwd() os.chdir(‘/tmp’) current_wkdir = os.getcwd() – Call the function. This will automatically store all the scrape data in a folder in your current working directory get_instagram_posts(username, startdate, enddate)
Any help I’d really appreciate!
Thanks!
I’ve made some small modifications to the 615_import_firefox_session.py script. I don’t use Firefox and my Instaloader installation is on a Linux headless server. What I do is:
This fixed the login problem for me, however a permanent fix in Instaloader itself would be the best approach.
Looks like you’re trying to run it on Python 2. Since this script uses f strings you’ll need Python 3.
Adam
I have the exact same problem. I noticed the issue just now.