# Can't Get Raw Request Payload in Flask with APM

**URL:** <https://discuss.elastic.co/t/cant-get-raw-request-payload-in-flask-with-apm/250258>\
**Category:** APM\
**Tags:** python\
**Created:** [September 28, 2020, 7:31pm UTC](https://discuss.elastic.co/t/cant-get-raw-request-payload-in-flask-with-apm/250258 "2020-09-28T19:31:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alsheh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alsheh/32/36799_2.png) [@Alsheh](https://discuss.elastic.co/u/Alsheh)\
**Post date:** [September 28, 2020, 7:31pm UTC](https://discuss.elastic.co/t/cant-get-raw-request-payload-in-flask-with-apm/250258/1 "2020-09-28T19:31:34Z")

</div>

Normally, I'm able to access the raw request payload in my Flask app using `request.get_data()` but I get an empty string when the APM agent is used. In Flask, I would need to call `request.get_data()` before accessing anything from the `request` object otherwise payload parsing would be triggered based on the `content-type` header. However, it seems like the python APM agent accesses the `request` object before I'm able to do so which triggers the payloads parsing and prevents me from accessing the raw request payload.

Currently, I have the APM agent turned off since retrieving the raw payload is crucial for my own use case to compute payload hashes but I'm wondering if anyone has any suggested solution to keep the APM on and still be able to get the raw payload?

Thanks!

_NOTE:_ APM agent version: `elastic-apm[flask]==5.4.3`

---

<div class="post-metadata">

**Author:** ![beniwohli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/beniwohli/32/21256_2.png) [@beniwohli](https://discuss.elastic.co/u/beniwohli)\
**Post date:** [September 29, 2020, 7:43am UTC](https://discuss.elastic.co/t/cant-get-raw-request-payload-in-flask-with-apm/250258/2 "2020-09-29T07:43:13Z")

</div>

Hey @Alsheh

Can you check if you have the [`capture_body`](https://www.elastic.co/guide/en/apm/agent/python/master/configuration.html#config-capture-body) config value set to `false`? We only look at the request body if that config option is set to `transactions`, `errors` or `all`. In your case where your code depends on the request body not being touched, I'd set it to `false`.

---

<div class="post-metadata">

**Author:** ![Alsheh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alsheh/32/36799_2.png) [@Alsheh](https://discuss.elastic.co/u/Alsheh)\
**Post date:** [October 7, 2020, 9:42pm UTC](https://discuss.elastic.co/t/cant-get-raw-request-payload-in-flask-with-apm/250258/3 "2020-10-07T21:42:14Z")

</div>

@beniwohli Thanks for your response! I'm unable to reproduce this issue since upgrading to `elastic-apm[flask]==5.9.0` .

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 28, 2020, 5:42pm UTC](https://discuss.elastic.co/t/cant-get-raw-request-payload-in-flask-with-apm/250258/4 "2020-10-28T17:42:22Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
