I have this code and I'm using python 3.7
def hash_password(password):
return bcrypt.hashpw(password.encode('utf8'), bcrypt.gensalt())
def credentials_valid(username, password):
with session_scope() as s:
user = s.query(User).filter(User.name.in_([username])).first()
if user:
return bcrypt.checkpw(password.encode('utf8'), user.password.encode('utf8'))
else:
return False
But when I try to run I get this error:
return bcrypt.checkpw(password.encode('utf8'), user.password.encode('utf8'))
AttributeError: 'bytes' object has no attribute 'encode'
AttributeError: 'bytes' object has no attribute 'encode'you can't encode byte to byte