# How do i edit a decoded deflated Json response using python script?

**URL:** <https://discourse.mitmproxy.org/t/how-do-i-edit-a-decoded-deflated-json-response-using-python-script/531>\
**Category:** Uncategorized\
**Created:** [June 25, 2017, 11:27pm UTC](https://discourse.mitmproxy.org/t/how-do-i-edit-a-decoded-deflated-json-response-using-python-script/531 "2017-06-25T23:27:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfonsorod2003](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@alfonsorod2003](https://discourse.mitmproxy.org/u/alfonsorod2003)\
**Post date:** [June 25, 2017, 11:27pm UTC](https://discourse.mitmproxy.org/t/how-do-i-edit-a-decoded-deflated-json-response-using-python-script/531/1 "2017-06-25T23:27:30Z")

</div>

I have tried everything and it doesn’t work. I tried to write the json response into a file but file is always empty. please help! ☹

---

<div class="post-metadata">

**Author:** ![Gigiarum](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/gigiarum/32/278_2.png) [@Gigiarum](https://discourse.mitmproxy.org/u/Gigiarum)\
**Post date:** [February 1, 2018, 2:25pm UTC](https://discourse.mitmproxy.org/t/how-do-i-edit-a-decoded-deflated-json-response-using-python-script/531/2 "2018-02-01T14:25:51Z")

</div>

I resume this thread.

My purpose is the same as alfonsorod2003 but in my script I get error when I try to access the text property of a response. The error is

> error when decoding b’\xac\x18 with ‘deflate’: error(‘Error -5 while decompressing data: incomplete or truncated stream’,)

I can normally get raw\_content.

If I start mitmproxy with -z option my script works without error and the client receives modified response.

---

<div class="post-metadata">

**Author:** ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)\
**Post date:** [February 1, 2018, 4:39pm UTC](https://discourse.mitmproxy.org/t/how-do-i-edit-a-decoded-deflated-json-response-using-python-script/531/3 "2018-02-01T16:39:13Z")

</div>

- `.raw_content`: The HTTP message body exactly as we receive it on the wire.
- `.content`: The HTTP message body decoded with the content-encoding header (e.g. gzip). This is still a Python bytes object.
- `.text`: The HTTP message body decoded with both content-encoding header (e.g. gzip) and content-type header charset. This is a Python str.

What gives?

1. Accessing `.raw_content` never fails.
2. Accessing `.content` may fail in the unlikely event that the server messes up the Content-Encoding.
3. Accessing `.text` may regularly fail because many websites don’t specify proper content types.

For 2 and 3, there are non-strict variants available as `get_content(strict=False)` and `get_text(strict=False)`.
