instagrapi
instagrapi copied to clipboard
I keep getting Unrecognized device alert emails
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
Use login_by_sessionid(sessionid: str)
login_by_sessionid
Where do i get this sessionid from ?
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.
I have the same problem in the first login.