File ".\core\users\login.py", line 22, in login_user
db_user = crud.get_Login(
File ".\api\crud.py", line 39, in get_Login
db_user.password.encode('utf-8'))
AttributeError: 'bytes' object has no attribute 'encode'
I got this error to relate to Base64 in Python
This is my core\users\login.py :
@router.post("/login")
def login_user(user: schemas.UserLogin, db: Session = Depends(get_db)):
db_user = crud.get_Login(
db, username=user.username, password=user.password)
if db_user == False:
raise HTTPException(status_code=400, detail="Wrong username/password")
return {"message": "User found"}
and api\crud.py :
def get_Login(db: Session, username: str, password: str):
db_user = db.query(models.UserInfo).filter(
models.UserInfo.username == username).first()
print(username, password)
pwd = bcrypt.checkpw(password.encode('utf-8'),
db_user.password.encode('utf-8'))
return pwd
I tried this solution and nothing work AttributeError: 'bytes' object has no attribute 'encode'; base64 encode a pdf file
decodebytes andencodestrings, but i tried multiple solutions and nothing work with medecodebytes andencodestrings" Well, what happened when you tried thinking about a) which of those you have in each case; b) which of those you want in each case? If you have abytesand want abytes, what should you do to convert it?