Form or File not working with APIRouter
See original GitHub issueFile as well as Form input is working in Fastapi object but not APIRouter object. This is not working – >
router = APIRouter()
@router.post("/profile/update-media")
async def update_media(
file: bytes = File(...)
):
return True
This is working —>
router = FastAPI()
@router.post("/profile/update-media")
async def update_media(
file: bytes = File(...)
):
return True
In APIRouter one I am getting key error in fastapi utils. Traceback-
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 388, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 45, in __call__
return await self.app(scope, receive, send)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\fastapi\applications.py", line 179, in __call__
await super().__call__(scope, receive, send)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\applications.py", line 111, in __call__
await self.middleware_stack(scope, receive, send)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
raise exc from None
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\middleware\base.py", line 25, in __call__
response = await self.dispatch_func(request, self.call_next)
File ".\app\main.py", line 50, in log_requests
response = await call_next(request)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\middleware\base.py", line 45, in call_next
task.result()
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\middleware\base.py", line 38, in coro
await self.app(scope, receive, send)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\middleware\cors.py", line 78, in __call__
await self.app(scope, receive, send)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\exceptions.py", line 82, in __call__
raise exc from None
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\routing.py", line 566, in __call__
await route.handle(scope, receive, send)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\routing.py", line 227, in handle
await self.app(scope, receive, send)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\starlette\routing.py", line 41, in app
response = await func(request)
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\fastapi\applications.py", line 128, in openapi
return JSONResponse(self.openapi())
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\fastapi\applications.py", line 106, in openapi
self.openapi_schema = get_openapi(
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\fastapi\openapi\utils.py", line 343, in get_openapi
definitions = get_model_definitions(
File "c:\users\aditya.shanbhog\appdata\local\programs\python\python38-32\lib\site-packages\fastapi\utils.py", line 28, in get_model_definitions
model_name = model_name_map[model]
KeyError:
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Bigger Applications - Multiple Files - FastAPI
The APIRouter s are not "mounted", they are not isolated from the rest of the application. This is because we want to include...
Read more >FastAPI with APIRouter plugin system not working
I'm trying to create a simple pluggable FastAPI application where plugins can add, or not, API endpoints.
Read more >RouterLinkActive - Angular
Tracks whether the linked route of an element is currently active, and allows you to specify one or more CSS classes to add...
Read more >FastAPI top-level dependencies - Sebastián Ramírez - Medium
from fastapi import APIRouterrouter = APIRouter() ... is that the tag and the dependency are mainly related to users.py , not to main.py...
Read more >Getting Started With FastAPI And More
Running this file with python main.py will boot up Uvicorn and FastAPI, ... from fastapi import APIRouter router = APIRouter( prefix='', ...
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
@ArcLightSlavik Thanks Its working now. Closing this issue.
Thanks for the help @ArcLightSlavik! 🚀
And thanks for coming back to close the issue @a-n-s ☕