subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.2k stars 667 forks source link

[BUG] JSONDecodeError for TOTP 2FA (Google Authenticator) #687

Open hittiks opened 2 years ago

hittiks commented 2 years ago

I am getting a JSONDecodeError exception when I try to perform two factor authentication with Google Authenticator. Am I doing something wrong or has Instagram changed the API?

Traceback:

Status 200: JSONDecodeError in private_request (user_id=10342827286, endpoint=/challenge/) >>> <!DOCTYPE html> (long html...) future: <Task finished coro=<Dispatcher._process_polling_updates() done, defined at /app/.heroku/python/lib/python3.7/site-packages/aiogram/dispatcher/dispatcher.py:407> exception=ClientJSONDecodeError('JSONDecodeError [Errno Expecting value] <!DOCTYPE html>\n<html lang="en" class="no-js logged-in client-root touch">\n <head>\n <meta charset="utf-8">\n (long html...) </script>\n </body>\n</html> instagrapi.exceptions.ClientJSONDecodeError: JSONDecodeError [Errno Expecting value] <!DOCTYPE html> (long html...) raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) requests.exceptions.JSONDecodeError: [Errno Expecting value] <!DOCTYPE html> (long html...)

adw0rd commented 2 years ago

@hittiks it looks like instagram has changed api, can you fix it?

hittiks commented 2 years ago

@adw0rd No, I can't fix it

hittiks commented 2 years ago

To recreate the behavior, you need to follow the link https://i.instagram.com/challenge/?next=/api/challenge/ (after 2FA)

So I tried to run that long HTML and got this page:

https://ibb.co/1GhWPyg

I am using Heroku to run my code in the cloud and passing this challenge from mobile can't solve the problem

Button "Это я" have this code (maybe it will be useful): <button name="choice" value="0" class="_5f5mN -fzfL KUBKM yZn4P ">Это я</button>

thmasker commented 2 years ago

Same error for me

hittiks commented 2 years ago

@adw0rd Well, I tried to fix it. I was able to go through that page and get {'location': 'instagram://checkpoint/dismiss', 'type': 'CHALLENGE_REDIRECTION', 'status': 'ok'} but so far I don't understand what I need to go further

mavenium commented 1 year ago

I have the same problem.

diezo commented 8 months ago

a quick fix:

pip install ensta

from ensta import Host

host = Host(username, password, totp_token=token)