Skip to content
Advertisement

TypeError: unsupported operand type(s) for &: ‘list’ and ‘QueryInstance’

I am trying to have a login system where user input will be crosschecked with tinydb’s json file. I managed to get the registration working but when I try logging in I got this error.

TypeError: unsupported operand type(s) for &: ‘list’ and ‘QueryInstance’

I tried removing password verification and it worked. Not entirely sure the reason behind it. Would be great if I can receive some guidance as to what went wrong. Thanks!

def login():
    username = input("Enter Username: ")
    password = input("Enter Password: ")
    User = Query()
    if(db.search(User.username == username) & (User.password == password)):
        print("Login Successful!")
        loggedInScreen()
    else:
        print("Incorrect Username or Password")
        login()

Advertisement

Answer

It should have been and not &. The operand and will check both the conditions that you are trying to validate whereas & does a bitwise AND and it doesn’t like the types of data provided for the bitwise AND, hence the error.

Advertisement