subzeroid / instagrapi

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

[BUG] Challenger not working #1041

Open h4ng3r opened 1 year ago

h4ng3r commented 1 year ago

Describe the bug

I implemented the challenge following the example:

insta = Client()
insta.challenge_code_handler = challenge_code_handler
insta.change_password_handler = change_password_handler
nsta.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD)

But the "challenge_code_handler" is not being called and I'm getting a ChallengeRequired exception.

To Reproduce Just run the example code with an account that requires email challenge.

Traceback

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/private.py", line 302, in _send_private_request
    response.raise_for_status()
  File "/home/pi/.local/lib/python3.10/site-packages/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/feed/reels_tray/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/private.py", line 438, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/private.py", line 334, 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 "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/private.py", line 302, in _send_private_request
    response.raise_for_status()
  File "/home/pi/.local/lib/python3.10/site-packages/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/feed/reels_tray/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/instagram/main.py", line 110, in <module>
    main()
  File "/home/pi/instagram/main.py", line 70, in main
    if insta.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD) == False:
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/auth.py", line 417, in login
    self.login_flow()
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/auth.py", line 167, in login_flow
    check_flow.append(self.get_reels_tray_feed("cold_start"))
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/auth.py", line 244, in get_reels_tray_feed
    return self.private_request("feed/reels_tray/", data)
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/private.py", line 455, in private_request
    return self._send_private_request(endpoint, **kwargs)
  File "/home/pi/.local/lib/python3.10/site-packages/instagrapi/mixins/private.py", line 334, in _send_private_request
    raise ChallengeRequired(**last_json)
instagrapi.exceptions.ChallengeRequired: challenge_required

Expected behavior According to documentation and the example the "challenge_code_handler" function should be called when IG requests a challenge.

Desktop (please complete the following information):

Thanks,

RogerVFbr commented 1 year ago

I'm getting an error when issuing "hashtag_info", seems to be related: ChallengeResolve: Unknown step_name "submit_phone" for "factsaboutus022" in challenge resolver: {'step_name': 'submit_phone', 'step_data': {'phone_number': 'None'}, 'flow_render_type': 3, 'bloks_action': 'com.instagram.challenge.navigation.take_challenge', 'cni': 17845117700910164, 'challenge_context': '{"step_name": "submit_phone", "cni": 17845117700910164, "is_stateless": false, "challenge_type_enum": "SMS", "present_as_modal": false}', 'challenge_type_enum_str': 'SMS', 'status': 'ok'}

jstchw commented 1 year ago

Having exactly the same issue as in the original post, any resolution?

adw0rd commented 1 year ago

@jstchw we are waiting for a decision from the community, you can help the project and send me a PR

nebula0225 commented 1 year ago

same for me don't work How to call ChallengeChoice ?

adw0rd commented 1 year ago

@nebula0225 what do you mean? Please provide examples of usage

nebula0225 commented 1 year ago

@adw0rd

I have a account that need have to solve challenge When i try login using that didn't go "challenge_code_handler" It just throw error "challenge_required"

def challenge_code_handler():
   # challenge my code
    return

cl = ig.Client()
cl.challenge_code_handler = challenge_code_handler
cl.login(USERNAME, PASSWORD)
adw0rd commented 1 year ago

@nebula0225 so what's the question? So that you don't define parameters, according to the documentation?

https://adw0rd.github.io/instagrapi/usage-guide/challenge_resolver.html

nebula0225 commented 1 year ago

@adw0rd No, The code above is just an example In fact, I worked by referring to that document. I think there are accounts where the challenge doesn't work. The account I tried did not have email and SMS information registered.

if login to web I saw warning and next input box for register email

adw0rd commented 1 year ago

If you reproduce this issue, then you can send your fixes in the form of a PR, or give me access to the instagram account username, password, proxy and mail access to get the code from isntagram.

Without this, I can't reproduce the problem.

My accounts work fine with the current challenge resolver

EchterAlsFake commented 1 year ago

Hey Guys,

I am facing the same Issue, but I have some new information.

When I try to do the challenge resolve stuff with a little test script

from instagrapi import Client

IG_USERNAME = "username..."
IG_PASSWORD = 'pass...'

def get_code_from_email(username):
    return input("Code lol:")

def get_code_from_sms(username):
    return input("Code lol:")

def challenge_code_handler(username, choice):
    if choice == ChallengeChoice.SMS:
        return get_code_from_sms(username)
    elif choice == ChallengeChoice.EMAIL:
        return get_code_from_email(username)
    return False

cl = Client()
cl.challenge_code_handler = challenge_code_handler
cl.login(IG_USERNAME, IG_PASSWORD)

the SMS code actually shows up on my phone. Seems like the API request for the challenge is working, but at some point there is an issue.

I think, the Issue is here:

Traceback (most recent call last): File "/home/asuna/PycharmProjects/Osintgram2/venv/lib/python3.11/site-packages/instagrapi/mixins/private.py", line 360, in _send_private_request response.raise_for_status() File "/home/asuna/PycharmProjects/Osintgram2/venv/lib/python3.11/site-packages/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/accounts/login/

because when I go to this URL, I get a HTTP 405 Error.

If you need my account credentials to reproduce the error, I can send them to you. I tested the script on 2 Accounts.

Hope that helps a little bit.

Thanks :)