-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to get request body in custom request formatter when using FastAPI #84
Comments
i would suggest u extend logging.Formatter for maximum flexibility, something like that json-logging-python/json_logging/__init__.py Line 267 in 8d6c1dd
|
Yes, I'm aware of them (and I've used them before with Flask). But the methods inside of this class ( |
@vstrimaitis is not really familiar with async await syntax. But will do some experiment once have time |
@vstrimaitis @bobbui I have the same issue. Have you found a solution? |
More information, see bobbui#84 With this patch, I can execute await self._request.body()
My solution: with this patch I can execute:
|
Hi @stephane-klein! I ended up making a custom middleware class which extends This is obviously not a clean solution in any sense, but it ended up working for me back when I needed it and the implementation has stayed the same since then 😅 |
I'm interested in getting the request body in a custom request formatter when using FastAPI. However,
request.body()
returns a coroutine and therefore requires theawait
keyword, but the_format_log_object
method is notasync
. My custom formatter looks something like this:Such an approach works in frameworks like Flask, where you don't have to use
await
to get the body, but fails for FastAPI. Do you have any suggestions on how to work around this?The text was updated successfully, but these errors were encountered: