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.

Form or File not working with APIRouter

See original GitHub issue

File 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
a-n-scommented, Sep 22, 2020

@ArcLightSlavik Thanks Its working now. Closing this issue.

0reactions
tiangolocommented, Nov 9, 2022

Thanks for the help @ArcLightSlavik! 🚀

And thanks for coming back to close the issue @a-n-s

Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I’m checking each one in order.

Read more comments on GitHub >

github_iconTop 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 >

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