Logo Pastebin.fr
Pastebin

Retrouvez, créez et partagez vos snippets en temps réel.

ihzoajzai

from fastapi import FastAPI, Request, HTTPException
import json

app = FastAPI()

@app.post("/endpoint")

async def receive_info(request: Request):
    # lire le body brut
    body = await request.body()
    print(body)

    # Parse le json
    try:
        data = json.loads(body)
    except json.JSONDecodeEror :
        raise HTTPException(status_code=400, detail="Invalid JSON") 

    # DEBUG

    print("Infos reçus :", data)
    return("status": "ok")

Créé il y a 4 semaines.

Rechercher un Pastebin

Aucun paste trouvé.