'ASGI callable returned without starting response

The fastAPI that I am working on does not return traceback whenever the request failed, instead, it returns 500 Internal Server Error with error :

ERROR:    ASGI callable returned without starting response.
2021-05-14 16:12:08 - uvicorn.error:409 - ERROR - ASGI callable returned without starting response.

Anyone experienced this problem before and know the fix to it ?



Solution 1:[1]

My issue was caused by a customize middleware. I've been able to update the middleware and fix this issue.

Solution 2:[2]

Most probably the __ call __ method of your middleware is not working well. I would advise checking a build in middleware and comparing with yours. E.g:

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Serena Xu
Solution 2 raghavsikaria