question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Login error: JSON decode fail, 403 - Forbidden.

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:18
  • Comments:41 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
twitter-79commented, Jun 9, 2021

This seems to be a problem with retrieving the csrf token

session.get('https://www.instagram.com/web/__mid/')
csrf_token = session.cookies.get_dict()['csrftoken']

in line 214 of instaloadercontext.py does not work for me while

res = session.get('https://www.instagram.com/accounts/login/')
csrf_token = re.findall(r"csrf_token\":\"(.*?)\"", res.text)[0]

is working fine!

7reactions
fatpandaclubcommented, Jun 3, 2021

I am a freelancer from India and I am facing no such issues… But one of my clients in France is facing the same issue… Could it be a Geographical issue?? But then again my other scripts which use different Instagram APIs seem to be working fine at his end… Can anyone please help???

I get this error in the EU, but if I set my VPN to India everything works just fine! So thanks for the tip 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I fix error 403 on python rest api?
I was having issues getting the json data but yesterday evening, the status code was 200 and I was able to see the...
Read more >
Instalooter not working : r/pythonhelp
Hello, every time i want to login to instalooter with ... this error message: "Fatal error: Login error: JSON decode fail, 403 -...
Read more >
HTTP status and error codes for JSON | Cloud Storage
403—Forbidden ; accountDisabled, The account associated with the project that owns the bucket or object has been disabled. Check the Google Cloud console...
Read more >
How to Fix a 403 Forbidden Error on Your WordPress Site
The 403 Forbidden error means that your server is working, but you no longer have permission to view all or some of your...
Read more >
Troubleshooting — Instaloader documentation
Login error ¶ ... Instaloader's login should work fine, both with and without Two-Factor-Authentication. It also supports handling the checkpoint challenge, issued ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found