Problems with using Depends FastApi method without Provide in wired module
See original GitHub issueHello, 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:
- Created 3 years ago
- Comments:12 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Lojka-oops yeah, it’s a bug I already report it, thanks for you answer.
Thank you very much for your help!