subzeroid / instagrapi

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

[BUG] `Client.media_edit()` failing with server returning a challenge with no [challenge][api_path] and status "fail" #799

Open kaijif opened 2 years ago

kaijif commented 2 years ago

Describe the bug A clear and concise description of what the bug is. When I try to edit a post, the Instagram servers reply with {'message': 'challenge_required', 'status': 'fail'}. Instagrapi attempts to get the challenge value, however, it does not exist. Therefore, it fails with KeyError: 'challenge' This only occurs on some accounts, others work fine. Also, when posting, the captions do not show up on posts. To Reproduce Provide a piece of code to reproduce the problem.

client.media_edit(post_to_edit.id, caption="some caption")

Traceback Show your full traceback so that it is clear where exactly the error occurred.

>>> client.media_edit(post_to_edit.id, caption="some caption")
printing last_json on line 54 of mixins/challenge.py
{'message': 'challenge_required', 'status': 'fail'}

Traceback (most recent call last):
  File "lib/instagrapi/mixins/private.py", line 298, in _send_private_request
    response.raise_for_status()
  File "lib/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://i.instagram.com/api/v1/media/2887152300700736288_52841477791/edit_media/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "lib/instagrapi/mixins/private.py", line 434, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "lib/instagrapi/mixins/private.py", line 330, in _send_private_request
    raise ChallengeRequired(**last_json)
instagrapi.exceptions.ChallengeRequired: challenge_required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lib/instagrapi/mixins/media.py", line 351, in media_edit
    result = self.private_request(
  File "lib/instagrapi/mixins/private.py", line 445, in private_request
    self.challenge_resolve(self.last_json)
  File "lib/instagrapi/mixins/challenge.py", line 55, in challenge_resolve
    challenge_url = last_json["challenge"]["api_path"]

Expected behavior A clear and concise description of what you expected to happen. The media_edit should succeed, or be prompted to solve a challenge. Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here. Requests through the app work just fine.

adw0rd commented 2 years ago

I can't reproduce, can you fix it yourself and send me PR?

kaijif commented 2 years ago

I would, but I'm not sure what's going wrong... I'm a bit new to this, do you have any ideas?

adw0rd commented 2 years ago

@kaijif no

Atomizer99 commented 1 year ago

Having the same issue