FastAPI在RequestValidationError异常处理程序中挂起等待

2024-05-23 14:36:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我想为验证错误创建一个自定义处理程序。因此,我创建了自己的异常处理程序:

@app.exception_handler(RequestValidationError)
async def validation_exception_handler(request: Request, exc):
    if "/couriers/" in request.url.path and request.method == "POST":
      
        data = await request.json()
        # Some logic

        return JSONResponse(content={"some": "content"}, status_code=400)

但是,显然,出于某种原因,它只是挂在await上。我可以很好地获得协同程序本身,但它从未被执行过(或者至少我想是这样)。为什么会这样


Tags: app处理程序asyncifrequestdef错误exception