question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems with using Depends FastApi method without Provide in wired module

See original GitHub issue

Hello, I am having difficulty implementing authorization using FastApi and Dependency Injection Framework. I am trying to do something like this:

from fastapi import Depends, APIRouter
from fastapi.security import HTTPBasic, HTTPBasicCredentials
from dependency_injector.wiring import inject, Provide

from services.some_service import SomeService
from containers import Container

router = APIRouter()
security = HTTPBasic()


@router.get("/users/me")
@inject
def read_current_user(
    some_service: SomeService = Depends(Provide[Container.some_service]),
    credentials: HTTPBasicCredentials = Depends(security)
):
    return {"username": credentials.username, "password": credentials.password}

But I am getting an error: AttributeError: 'HTTPBasic' object has no attribute 'provider'. I tried to add HTTPBasic to the container and use from there, it fixed the error, but the authorization still didn’t work. I am clearly missing something. Is there a template for this? Thanks in advance for your help with this issue!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
juanmarin96commented, Dec 5, 2020

@Lojka-oops yeah, it’s a bug I already report it, thanks for you answer.

1reaction
Lojka-oopscommented, Dec 5, 2020

Thank you very much for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependencies - First Steps - FastAPI - tiangolo
Declare the dependency, in the "dependant"¶. The same way you use Body , Query , etc. with your path operation function parameters, use...
Read more >
python - Unable to inject dependencies to FastAPI endpoints
I've read a bit about the use of pydantic in FastAPI and I see why I get this error, but I'm stuck at...
Read more >
Wiring — Dependency Injector 4.41.0 documentation
Wiring feature provides a way to inject container providers into the functions and methods. To use wiring you need: Place @inject decorator.
Read more >
The Ultimate FastAPI Tutorial Part 11 - Dependency Injection ...
Add a parameter to your path operation function (i.e. the decorated API endpoint function), using the FastAPI Depends class to define the ...
Read more >
fastapi_permissions - PyPI
from fastapi import Depends, FastAPI from fastapi.security import ... There are some things you must provide before using the permissions system:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found