instagrapi icon indicating copy to clipboard operation
instagrapi copied to clipboard

I keep getting Unrecognized device alert emails

Open viralcode opened this issue 1 year ago • 4 comments

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

  • OS: Ubuntu
  • instagrapi version instagrapi == 1.19.7

viralcode avatar Jan 12 '24 19:01 viralcode

Use login_by_sessionid(sessionid: str)

tajbowness avatar Jan 16 '24 02:01 tajbowness

login_by_sessionid

Where do i get this sessionid from ?

viralcode avatar Jan 16 '24 03:01 viralcode

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.

tajbowness avatar Jan 16 '24 22:01 tajbowness

I have the same problem in the first login.

mavenium avatar Aug 18 '24 06:08 mavenium