subzeroid / instagrapi

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

Status 200: JSONDecodeError in private_request (user_id=39633833976, endpoint=/challenge/) #907

Open SaeedFazlollahzadeh opened 2 years ago

SaeedFazlollahzadeh commented 2 years ago

Hi, this is my code:

from pathlib import Path
from PIL import Image
from instagrapi import Client
import json

image = Image.open("picture.jpg")
image = image.convert("RGB")
new_image = image.resize((1080, 1080))
new_image.save("new_picture.jpg")

username = 'USER'
password = 'PASSWORD'
verification_code = '021214'

cl = Client()
cl.login(username, password, verification_code=verification_code)
# to dump session
# json.dump(
#    cl.get_settings(),
#    open('./cookies.json', 'w')
#)
# to load saved session
# cl = Client(json.load(open('/path/to/cookies.json')))
# cl.user_following(user_id='USERID', amount=0)
# cl.logout()
# cl.relogin()

photo_path = "new_picture.jpg"
photo_path = Path(photo_path)

cl.photo_upload(photo_path, "hello this is a test from instagrapi")

But I get this error. That's a very big, but I only paste some lines: First line:

Status 200: JSONDecodeError in private_request (user_id=USERID, endpoint=/challenge/) >>> <!DOCTYPE html>

Middle lines:

: 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Saeed\Desktop\python-projects\instagrapi\test.py", line 18, in <module>
    cl.login(username, password, verification_code='348438')
  File "C:\Users\Saeed\Desktop\python-projects\venv\lib\site-packages\instagrapi\mixins\auth.py", line 418, in login
    self.login_flow()
  File "C:\Users\Saeed\Desktop\python-projects\venv\lib\site-packages\instagrapi\mixins\auth.py", line 167, in login_flow
    check_flow.append(self.get_reels_tray_feed("cold_start"))
  File "C:\Users\Saeed\Desktop\python-projects\venv\lib\site-packages\instagrapi\mixins\auth.py", line 244, in get_reels_tray_feed
    return self.private_request("feed/reels_tray/", data)
  File "C:\Users\Saeed\Desktop\python-projects\venv\lib\site-packages\instagrapi\mixins\private.py", line 445, in private_request
    self.challenge_resolve(self.last_json)
  File "C:\Users\Saeed\Desktop\python-projects\venv\lib\site-packages\instagrapi\mixins\challenge.py", line 78, in challenge_resolve
    return self.challenge_resolve_simple(challenge_url)
  File "C:\Users\Saeed\Desktop\python-projects\venv\lib\site-packages\instagrapi\mixins\challenge.py", line 364, in challenge_resolve_simple
    self._send_private_request(challenge_url, {"choice": "0"})
  File "C:\Users\Saeed\Desktop\python-projects\venv\lib\site-packages\instagrapi\mixins\private.py", line 310, in _send_private_request
    raise ClientJSONDecodeError(
instagrapi.exceptions.ClientJSONDecodeError: JSONDecodeError [Errno Expecting value] <!DOCTYPE html>

Last line:

: 0 while opening https://i.instagram.com/challenge/?next=/api/challenge/

Do you please help me why I am getting this error? Is it related to any challenge as in the last line?

mavenium commented 2 years ago

I have the same problem.

88um commented 2 years ago

You can add this solution to your challenge.py: Issue