Previously, I asked How to get data received in Flask request because
request.data was empty. The answer explained that
request.data is the raw post body, but will be empty if form data is parsed. How can I get the raw post body unconditionally?
@app.route('/', methods=['POST']) def parse_request(): data = request.data # empty in some cases # always need raw data here, not parsed form data
This question is tagged with
~ Asked on 2012-06-12 15:37:10
request.get_data() to get the raw data, regardless of content type. The data is cached and you can subsequently access
request.form at will.
If you access
request.data first, it will call
get_data with an argument to parse form data first. If the request has a form content type (
application/x-url-encoded) then the raw data will be consumed.
request.json will appear empty in this case.
~ Answered on 2014-05-27 21:06:57
request.stream is the stream of raw data passed to the application by the WSGI server. No parsing is done when reading it, although you usually want
data = request.stream.read()
The stream will be empty if it was previously read by
request.data or another attribute.
~ Answered on 2012-06-12 16:25:25