# How can I save all requests/responses to a file?

**URL:** <https://discourse.mitmproxy.org/t/how-can-i-save-all-requests-responses-to-a-file/122>\
**Category:** Uncategorized\
**Created:** [August 1, 2016, 6:43pm UTC](https://discourse.mitmproxy.org/t/how-can-i-save-all-requests-responses-to-a-file/122 "2016-08-01T18:43:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![valyard](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/valyard/32/45_2.png) [@valyard](https://discourse.mitmproxy.org/u/valyard)\
**Post date:** [August 1, 2016, 6:43pm UTC](https://discourse.mitmproxy.org/t/how-can-i-save-all-requests-responses-to-a-file/122/1 "2016-08-01T18:43:57Z")

</div>

Hi.

I’m looking at an encrypted connection and want to save decrypted data in “time|request|response” format.  
Like going into each request and pressing P in mitmproxy. What is the easiest way to do this?

---

<div class="post-metadata">

**Author:** ![valyard](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/valyard/32/45_2.png) [@valyard](https://discourse.mitmproxy.org/u/valyard)\
**Post date:** [August 1, 2016, 8:02pm UTC](https://discourse.mitmproxy.org/t/how-can-i-save-all-requests-responses-to-a-file/122/2 "2016-08-01T20:02:57Z")

</div>

OK, this script seems to be working.  
The site has some outdated examples though o.O

`import random  
import sys

from mitmproxy.models import decoded  
import time

def start(context, argv):  
context.folder = argv[1]

def response(context, flow):  
t = time.time()\*1000  
f = open("%s/%d.request" % (context.folder,t), “wb”)  
with decoded(flow.request):  
f.write(flow.request.content)

```
f = open("%s/%d.response" % (context.folder,t), "wb")
with decoded(flow.response):
    f.write(flow.response.content)

```

`

---

<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:** [August 9, 2016, 1:48am UTC](https://discourse.mitmproxy.org/t/how-can-i-save-all-requests-responses-to-a-file/122/3 "2016-08-09T01:48:24Z")

</div>

Thanks for updating your question with an answer yourself 🙂

> [@valyard](#):
>
> The site

Which site and where?

---

<div class="post-metadata">

**Author:** ![valyard](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/valyard/32/45_2.png) [@valyard](https://discourse.mitmproxy.org/u/valyard)\
**Post date:** [August 9, 2016, 7:04am UTC](https://discourse.mitmproxy.org/t/how-can-i-save-all-requests-responses-to-a-file/122/4 "2016-08-09T07:04:04Z")

</div>

Github. While I was browsing examples and reading docs I noticed that some of the examples seemed to be outdated comparing to docs. Don’t remember which ones already/.

---

<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:** [August 10, 2016, 4:23am UTC](https://discourse.mitmproxy.org/t/how-can-i-save-all-requests-responses-to-a-file/122/5 "2016-08-10T04:23:05Z")

</div>

Thanks. You most likely browsed the examples on the master branch, which work on master but not on 0.17.
