Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'bcrypt' has no attribute '__about__' with new 4.1.1 version #85

Open
ArtemBalandin81 opened this issue Jul 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ArtemBalandin81
Copy link
Owner

ArtemBalandin81 commented Jul 11, 2024

#Why
При авторизации возникает ошибка в логах, которая ни на что не влияет:
AttributeError: module 'bcrypt' has no attribute '__about__' with new 4.1.1 version
Ссылка на обсуждение ошибки

Причина:

  • This is an issue with how passlib attempts to read a version (for logging only) and fails because it's loading modules that no longer exist in bcrypt 4.1.x.
  • passlib seems to be abandoned and the new bcrypt doesn't work with it.

#How to do

  • Предложено либо даунгрейдить bcrypt до Needs to force bcrypt==4.0.1 to keep using passli
  • Поскольку это warning, можно его "заглушить" в настройках логгера:
    As the OP indicates here, passlib will work with latest bcrypt, it simply emits a warning. You should be able to silence that warning with a logging configuration.
    logging.getLogger('passlib').setLevel(logging.ERROR)
  • Либо отказаться от passlib совсем, заимствовав требуемые методы:
I resolved it by removing the passlib module and simply using the bcrypt directly for hashing and verification :

import bcrypt

# Hash a password using bcrypt
def hash_password(password):
    pwd_bytes = password.encode('utf-8')
    salt = bcrypt.gensalt()
    hashed_password = bcrypt.hashpw(password=pwd_bytes, salt=salt)
    return hashed_password

# Check if the provided password matches the stored password (hashed)
def verify_password(plain_password, hashed_password):
    password_byte_enc = plain_password.encode('utf-8')
    return bcrypt.checkpw(password = password_byte_enc , hashed_password = hashed_password)
  • Поскольку у нас используется FastApi Users, необходимо проверить можно ли безболезненно отказаться от passlib
@ArtemBalandin81 ArtemBalandin81 added the bug Something isn't working label Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant