Menu Close

How to get raw POST body in Python Flask regardless of Content-Type header?

Sometimes, we want to get raw POST body in Python Flask regardless of Content-Type header.

In this article, we’ll look at how to get raw POST body in Python Flask regardless of Content-Type header.

How to get raw POST body in Python Flask regardless of Content-Type header?

To get raw POST body in Python Flask regardless of Content-Type header, we call request.stream.read.

For instance, we write

data = request.stream.read()

to get the raw data from the request that’s passed by the WSGI server to the Flask app and read it.

Conclusion

To get raw POST body in Python Flask regardless of Content-Type header, we call request.stream.read.

Posted in Python, Python Answers