Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(trapped) error reading bcrypt version v.4.1.2

Tags:

python

bcrypt

I am programming an API with FastAPI and also using the module bcrypt==4.1.2

When running the app I get the following error:

...
INFO:     Finished server process [24084]
INFO:     Started server process [3256]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
(trapped) error reading bcrypt version
Traceback (most recent call last):
  File "D:\xnet_api\.venv\Lib\site-packages\passlib\handlers\bcrypt.py", line 620, in _load_backend_mixin
    version = _bcrypt.__about__.__version__
              ^^^^^^^^^^^^^^^^^
AttributeError: module 'bcrypt' has no attribute '__about__'
INFO:     127.0.0.1:53814 - "POST /user/login HTTP/1.1" 200 OK

In an old Github post I read that this is a bug with bycrypt: https://github.com/langflow-ai/langflow/issues/1173#issuecomment-1839591335

Hey. This is a bug on passlib. I'll try to push an update on that ASAP.

The issue is bcrypt's version has to be pinned at 4.0.1 until they fix it in passlib.

However, this was a long time ago and the error still exists. When I use version 4.0.1, the error no longer occurs. However, version 4.1.2 is already available and I would like to use the latest version.

My question is, is there a way to fix the error? Can I simply ignore the error?

like image 513
flo Avatar asked Mar 31 '26 17:03

flo


1 Answers

The issue comes from an outdated Passlib installation (last public release was ~4 years ago, no recent signs of active development). If you don’t specifically need Passlib, the easiest fix is to drop it and use bcrypt directly, eg:

    import bcrypt

    def verify_password(plain_password: str, hashed_password: str) -> bool:
        return bcrypt.checkpw(plain_password.encode("utf-8"), hashed_password.encode("utf-8"))

    def get_password_hash(password: str) -> str:
        return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8")

This avoids any dependency issues and keeps things simple. You can still use Passlib for other reasons, although, due to maintenance issues [1], consider alternatives [2].

  1. https://foss.heptapod.net/python-libs/passlib/-/issues/187
  2. https://pypi.org/project/pwdlib/
like image 196
Maciej Kwas Avatar answered Apr 03 '26 07:04

Maciej Kwas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!