我正在处理的fastAPI在请求失败时不会返回回溯,而是返回500内部服务器错误并返回错误:
ERROR: ASGI callable returned without starting response.
2021-05-14 16:12:08 - uvicorn.error:409 - ERROR - ASGI callable returned without starting response.
有人以前经历过这个问题并知道解决方法吗?
很可能中间件的__ call __
方法工作不好。我建议检查一个内置的中间件,并与您的进行比较。例如:
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if scope["type"] != "http":
await self.app(scope, receive, send)
return
request = Request(scope, receive=receive)
response = await self.dispatch_func(request, self.call_next)
await response(scope, receive, send)
我的问题是由自定义中间件引起的。我已经能够更新中间件并解决这个问题。