Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

python - 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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...