Skip to content

passlib.exc.MissingBackendError: bcrypt: no backends available -- recommend you install one (e.g. 'pip install bcrypt')

0

I am using fastAPI and deployed API in Lambda functions. when testing login API (passlib[bcrypt] is used to hash password) throwing an Internal Server Error.

Traceback (most recent call last):
  File "/var/task/mangum/protocols/http.py", line 58, in run
    await app(self.scope, self.receive, self.send)
  File "/var/task/fastapi/applications.py", line 282, in __call__
    await super().__call__(scope, receive, send)
  File "/var/task/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/var/task/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/var/task/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/var/task/starlette/middleware/cors.py", line 83, in __call__
    await self.app(scope, receive, send)
  File "/var/task/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/var/task/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/var/task/fastapi/middleware/asyncexitstack.py", line 20, in __call__
    raise e
  File "/var/task/fastapi/middleware/asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "/var/task/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/var/task/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/var/task/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/var/task/fastapi/routing.py", line 241, in app
    raw_response = await run_endpoint_function(
  File "/var/task/fastapi/routing.py", line 169, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/var/task/starlette/concurrency.py", line 41, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "/var/task/anyio/to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/var/task/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "/var/task/anyio/_backends/_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "/var/task/routes/users.py", line 28, in login
    if user and verify_password(form_data.password, user.password):
  File "/var/task/crud.py", line 15, in verify_password
    return pwd_context.verify(plain_password, hashed_password)
  File "/var/task/passlib/context.py", line 2347, in verify
    return record.verify(secret, hash, **kwds)
  File "/var/task/passlib/utils/handlers.py", line 792, in verify
    return consteq(self._calc_checksum(secret), chk)
  File "/var/task/passlib/handlers/bcrypt.py", line 591, in _calc_checksum
    self._stub_requires_backend()
  File "/var/task/passlib/utils/handlers.py", line 2254, in _stub_requires_backend
    cls.set_backend()
  File "/var/task/passlib/utils/handlers.py", line 2156, in set_backend
    return owner.set_backend(name, dryrun=dryrun)
  File "/var/task/passlib/utils/handlers.py", line 2176, in set_backend
    raise default_error
passlib.exc.MissingBackendError: bcrypt: no backends available -- recommend you install one (e.g. 'pip install bcrypt')

python 3.10

which version is compatible with lambda?

asked 3 years ago1.7K views
1 Answer
1
Accepted Answer

As per ref https://stackoverflow.com/questions/56720614/bcrypt-does-not-work-on-lambda-serverless

To resolve the issue you're encountering with bcrypt in a AWS Lambda environment, you need to install the Linux version of the package and its dependencies (cffi, cryptography, and PyNaCl).

The following commands should be adjusted to match your project structure and Python version:

pip download PyNaCl --platform manylinux1_x86_64 --no-deps -d lambda_project/python/lib/python3.8/site-packages
pip download cffi --platform manylinux1_x86_64 --no-deps -d lambda_project/python/lib/python3.8/site-packages
pip download bcrypt --platform manylinux1_x86_64 --no-deps -d lambda_project/python/lib/python3.8/site-packages
pip download cryptography --platform manylinux2014_x86_64 --no-deps -d lambda_project/python/lib/python3.8/site-packages

cd lambda_project/python/lib/python3.8/site-packages
unzip \*.whl
rm *.whl
EXPERT
answered 3 years ago
  • should I follow the same for rest of the packages?

  • I didn't include cryptography it was throwing an error. and increased Timeout to 5 sec in lambda configuration

  • Thank for the additional comment

  • lambda is taking long time to fetch login and signup API both are using bcrypt to hash password, can we minimize the time?

  • let me check and back to you

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.