Prevents access to request raw data in Flask
See original GitHub issueThis all seems to be a bit of a mess, but if you want to access the raw request data in Flask regardless of the content type (I can’t control the client), you need to call
request.get_data()
and you need to do this before accessing request.data or request.form, because both of these will call get_data() in such a way that the stream will be exhausted, parsed into the form dict, and the raw data is never cached.
This doesn’t seem documented except in the comments: https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/wrappers.py#L440
Should the sentry extension call request.get_data() first to make sure the raw data is cached before using request.form?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:6
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How To Process Incoming Request Data in Flask - DigitalOcean
The request object holds all incoming data from the request, which includes the mimetype, referrer, IP address, raw data, HTTP method, and ...
Read more >Get raw POST body in Python Flask regardless of Content ...
Use request.get_data() to get the raw data, regardless of content type. The data is cached and you can subsequently access request.data ...
Read more >API — Flask Documentation (2.2.x)
A data structure of functions to call at the end of each request, in the format {scope: [functions]} . The scope key is...
Read more >How to Process Incoming Request Data in Flask - YouTube
In this video I talk about how to process incoming data in Flask. I cover three cases: url parameters (query arguments), form data, ......
Read more >Flask by Example – Text Processing with Requests ...
by Real Python 35 Comments data-science flask web-dev ... Free Bonus: Click here to get access to a free Flask + Python video...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve run into this issue also recently.
It makes sense that Flask doesn’t want to cache the unparsed body. This could be really large in the case of file uploads. Triggering the caching is probably not best for all scenarios.
This is working for me right now
There might still be a better, more general solution. I’m not sure if the code that captures
request.form
could just be moved into anafter_request
and still have the same results?For what it’s worth the new sentry-python SDK makes this configurable and generally is less invasive for accessing this information.