subzeroid / instagrapi

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

[BUG] delta_login_review method outdated #686

Open 88um opened 2 years ago

88um commented 2 years ago

This occurs when an unknown device logs into your account. From there, you are prompted with a challenge screen to either accept the login or not. The method currently included in the challenge class is outdated and produces this traceback:

from instagrapi import Client
c = Client()
c.login_by_sessionid("susblockedsession")
c.get_timeline_feed()

 File "C:\Users\viral\AppData\Local\Programs\Python\Python39\lib\site-packages\instagrapi\mixins\auth.py", line 215, in get_timeline_feed
    return self.private_request(
  File "C:\Users\viral\AppData\Local\Programs\Python\Python39\lib\site-packages\instagrapi\mixins\private.py", line 443, in private_request
    self.challenge_resolve(self.last_json)
  File "C:\Users\viral\AppData\Local\Programs\Python\Python39\lib\site-packages\instagrapi\mixins\challenge.py", line 78, in challenge_resolve
    return self.challenge_resolve_simple(challenge_url)
  File "C:\Users\viral\AppData\Local\Programs\Python\Python39\lib\site-packages\instagrapi\mixins\challenge.py", line 365, in challenge_resolve_simple
   self._send_private_request(challenge_url, data={"choice":"0"})
  File "C:\Users\viral\AppData\Local\Programs\Python\Python39\lib\site-packages\instagrapi\mixins\private.py", line 310, in _send_private_request
    raise ClientJSONDecodeError(
instagrapi.exceptions.ClientJSONDecodeError: JSONDecodeError Expecting value: line 1 column 1 (char 0) while opening https://i.instagram.com/challenge/?next=/api/challenge/

I have a few accounts that have a suspicious login challenge screen. I do not have the emails or numbers attached to them, however I do have the session IDs in which I used this simple fix to accept the login challenge.

Using burpsuite, I re-simulated the suspicious login process on one of my accounts and found a different endpoint to use as an alternative. I ended up changing a few lines of the challenge_resolve_simple method in challenge.py:

def challenge_resolve_simple(self, challenge_url: str) -> bool:
        """
        Old type (through private api) challenge resolver
        Помогите нам удостовериться, что вы владеете этим аккаунтом

        Parameters
        ----------
        challenge_url : str
            Challenge URL

        Returns
        -------
        bool
            A boolean value
        """
        step_name = self.last_json.get("step_name", "")
        if step_name == "delta_login_review":

            # New endpoint
            endpoint = "bloks/apps/com.instagram.challenge.navigation.take_challenge/" 

            # New encoded data
            data = f"should_promote_account_status=0&choice=0&_uuid={self.uuid}&bk_client_context=%7B%22bloks_version%22%3A%2254a609be99b71e070ffecba098354aa8615da5ac4ebc1e44bb7be28e5b244972%22%2C%22styles_id%22%3A%22instagram%22%7D&bloks_versioning_id=54a609be99b71e070ffecba098354aa8615da5ac4ebc1e44bb7be28e5b244972" 

            accepted =self._send_private_request(endpoint, data=data,with_signature=False) 

            # ==> Json Response/ Test if it was successful
            if accepted.get("status")=="ok":
                print("Accepted delta_login challenge")  
                return True
            else:
                print("Failed to accept delta_login challenge")
                return False
mavenium commented 2 years ago

Hi, I had the same problem and this solution works for me. thank you.