The request's content-type
is application/json
, but I want to get the request body bytes. Flask will auto convert the data to json
. How do I get the request body?
You can get the non-form-related data by calling request.get_data()
You can get the parsed form data by accessing request.form
and request.files
.
However, the order in which you access these two will change what is returned from get_data
. If you call it first, it will contain the full request body, including the raw form data. If you call it second, it will typically be empty, and form
will be populated. If you want consistent behavior, call request.get_data(parse_form_data=True)
.
You can get the body parsed as JSON by using request.get_json()
, but this does not happen automatically like your question suggests.
See the docs on dealing with request data for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With