[Python] fastapi will messing sorted dictionary up

Discussão em 'Python' iniciado por Stack, Dezembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    Although I am returning a sorted dictionary by value, FastAPI response is not sorted.

    I'm using

    • python: 3.8.10
    • fastapi: 0.95.2
    This is my endpoint:


    @classifier_router.post("/groupClassifier")
    async def group_classifier(
    # current_user: User = Depends(get_current_user),
    group_id: str = Query(default="1069302375", description=GROUP_ID_DESC),
    starttime: Union[datetime , None] = DEFAULT_START_TIME,
    endtime: Union[datetime , None] = DEFAULT_END_TIME):
    result = handler.group_classifier(
    [group_id],
    starttime,
    endtime)
    if result==None:
    raise HTTPException(
    status_code=500
    )
    else:
    return result

    Result which returned in swagger:


    {
    "class_scores": {
    "1": 34.8,
    "2": 22.1,
    "3": 16.9,
    "4": 7.8,
    "5": 26,
    "6": 23.6
    }
    }

    Continue reading...

Compartilhe esta Página