instagrapi icon indicating copy to clipboard operation
instagrapi copied to clipboard

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

Open kaijif opened this issue 2 years ago • 3 comments

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):

  • OS: Ubuntu 21.04
  • Python version 3.9.12
  • instagrapi version 1.16.25

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

kaijif avatar Jul 21 '22 21:07 kaijif

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

adw0rd avatar Jul 21 '22 22:07 adw0rd

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

kaijif avatar Jul 21 '22 22:07 kaijif

@kaijif no

adw0rd avatar Jul 22 '22 11:07 adw0rd

Having the same issue

Atomizer99 avatar Feb 08 '23 20:02 Atomizer99