I going to Python from C# for a few days and don't know how to get callback functions in Python?
Please advise how I can find out if the login was successful and otherwise give me a chance to retry the next password?
import instaloader
from getpass import getpass
L = instaloader.Instaloader()
USER = input('Enter Instagram Username: ')
PASSWORD = getpass('Enter Password: ')
L.login(USER, PASSWORD)
if (L.Login ??) # how to check if login was successful?
profile = instaloader.Profile.from_username(L.context, USER)
# print follower names for test...
for f in profile.get_followers():
print(f.username)
hint: code wrote in python 3.10
CodePudding user response:
You could try something like this. When the Password is wrong it'll continue the loop and have the person try their credentials again if it causes an error due to invalid login.
import instaloader
from getpass import getpass
L = instaloader.Instaloader()
USER = input('Enter Instagram Username: ')
while True:
try:
PASSWORD = getpass('Enter Password: ')
L.login(USER, PASSWORD)
break
except:
print("Wrong Password")