What I’m trying to do:
I’m trying to authenticate my users with anvil.users.login_with_email What I’ve tried and what’s not working:
I currently have 3 users (gmwebman, nickb, martinc) with their passwords the same as their usernames for testing. If on my login form I provide correct credentials the user is successfully logged in. If I supply an incorrect password I get a TypeError instead of AuthenticationFailed : TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types at frmLogin, line 43
Code Sample:
# this is a formatted code snippet.
def btnLogin_click(self, **event_args):
pass
if self.txtUsername.text == '':
alert('Please enter your username')
elif self.txtPassword.text == '':
alert('Please enter your password')
else:
uu = app_tables.users.search()
un = ''
em = ''
for u in uu:
if u['username'] == self.txtUsername.text:
un = u['username']
em = u['email']
if un == '':
alert('Login failed. No such username.')
else:
pw = self.txtPassword.text
try:
43 user = anvil.users.login_with_email(em, pw)
if user['isadmin']:
alert('Administrator has logged in.')
else:
alert('User has logged in.')
except 'AuthenticationFailed':
alert('Login failed. Incorrect password.')
# paste your code between ```
When I cloned your app and played with it, I regularly saw the error you’re seeing when I entered in a username with a garbage password. If I entered the correct password, the user logged in successfully.
I created a new app to test with, and in that one entering the wrong password gets the expected “wrong password” error message, not the error you’re seeing.
I created a new app with nothing but a custom login form. Initially I did not put the “anvil.users.login_with_email” in a try block. A correct username and password produced a successful login, an incorrect password produced the expected “AuthenticationFailed” exception.
I then put the login in a try block with an except block to catch the above:
except ‘AuthenticationFailed’:
As before a correct username+password produced a successful login but an incorrect password produced the weird TypeError: isinstance() exception. The weirdness only appears when the login is in a try!