I'm new to using instagrapi and I want to understand if there is a way to automate the confirmation code process.
from instagrapi import Client
cl = Client()
cl.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD)
user_id = cl.user_id_from_username("adw0rd")
medias = cl.user_medias(user_id, 20)
Every time I run the code, the verification code sent to my email is required. It's not sustainable for the app I want to make.
you should not try and login each and everytime, thats not human behaivor and is suspicious to say the lease - always try to login using stored session information. here's an example from the API docs; for first login:
and for the next time you login:
that way you can prevent instagram from asking you for a verification code each and every time. more on this and best practices: https://subzeroid.github.io/instagrapi/usage-guide/best-practices.html
Now when it comes for extracting the verification code, you can simply catch the exception 'ChallengeRequired' and handle it by using the email and imaplib libraries like so:
this code inside the handler should do the trick. too see how to implement it inside your code please refer here: https://subzeroid.github.io/instagrapi/usage-guide/challenge_resolver.html
goodluck :)