[Python] How to solve a 422 status code error in FastAPI with path parameters?

Discussão em 'Python' iniciado por Stack, Julho 28, 2025.

  1. Stack

    Stack Membro Participativo

    I am using FastAPI where I am trying to create a route to call a function in a Service with the signature

    @router.get("/notes/{keynote}/{mode}/{clef}")
    def get_notes(keynote_id: int, mode_id: int, clef_id: int):


    I know this function works as designed.

    In postman I am sending:

    GET http://localhost:8000/scale/notes/16/1/2


    I get the response:

    422 Unprocessable entity


    With the following response body:

    {"detail":[{"type":"missing","loc":["query","keynote_id"],"msg":"Field required","input":null},{"type":"missing","loc":["query","mode_id"],"msg":"Field required","input":null},{"type":"missing","loc":["query","clef_id"],"msg":"Field required","input":null}]}


    Is this an invalid route? Is there a better way of routing so that I can send 3 parameters?

    I did a direct call to the underlying code and received the correct data, so I know the function works and the error must be the routing.

    All my other routing code in the API works - but each has only 1 parameter e.g.

    @router.get("/{family_id}")
    def get_options_by_family(family_id: int):

    Continue reading...

Compartilhe esta Página