subzeroid / instagrapi

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

I keep getting Unrecognized device alert emails #1744

Open viralcode opened 9 months ago

viralcode commented 9 months ago

Describe the bug

I keep getting Unrecognized device alert emails from instagram. I have my app hosted on digital ocean and i use a proxy from proxy seller.

I tried the challenge handlers but none of them are triggering for some reason. How do i fix this ?


try:
        cl = Client()

        cl.challenge_code_handler = challenge_code_handler
        cl.change_password_handler = change_password_handler

        # Set proxy settings
        proxy_dsn = f"http://{PROXY_USERNAME}:{PROXY_PASSWORD}@{PROXY_HOST}:{PROXY_PORT}"
        cl.set_proxy(proxy_dsn)

        if data.verification_code:
            cl.login(data.username, data.password, verification_code=data.verification_code)
        else:
            cl.login(data.username, data.password)
        generated_uuid = uuid.uuid4()
        cl.dump_settings(f"data/{generated_uuid}.json")
        user = cl.user_info_by_username(data.username)
        return {"user_id": user.pk, "pfp_url": user.profile_pic_url_hd, "uuid": generated_uuid}

    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

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

Desktop (please complete the following information):

tajbowness commented 9 months ago

Use login_by_sessionid(sessionid: str)

viralcode commented 9 months ago

login_by_sessionid

Where do i get this sessionid from ?

tajbowness commented 9 months ago

When you've cl.dump_settings(f"data/{generated_uuid}.json") it created a json with ur login session info. you can find it in their, format like this:

user_settings = cl.load_settings(path to folder) cl.login_by_sessionid(user_settings["authorization_data"]["sessionid"])

Here is an alternative:

cl.login(username, password)

ONLY use the alternative when instagram prompts you with a loginrequired exception, instagram has signed you out and wants you to sign in again. When you relog generate session info and delete the previous, dump the settings and when you relog reuse the newly dumped settings.

mavenium commented 2 months ago

I have the same problem in the first login.