# Request redirect not working for using static data

**URL:** <https://discourse.mitmproxy.org/t/request-redirect-not-working-for-using-static-data/90>\
**Category:** help\
**Created:** [July 20, 2016, 12:33am UTC](https://discourse.mitmproxy.org/t/request-redirect-not-working-for-using-static-data/90 "2016-07-20T00:33:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shrikantkaramkar](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@shrikantkaramkar](https://discourse.mitmproxy.org/u/shrikantkaramkar)\
**Post date:** [July 20, 2016, 12:33am UTC](https://discourse.mitmproxy.org/t/request-redirect-not-working-for-using-static-data/90/1 "2016-07-20T00:33:53Z")

</div>

I am trying to use the redirect request example in my project but it is not working.  
What I am doing:

- I have a stored json for example \<user.json\>
- I am planning to, pass this json when I capture user\_url: /account/user

```auto
"""
This example shows two ways to redirect flows to other destinations.
"""
from libmproxy.models import HTTPResponse
from netlib.http import Headers

def request(context, flow):

    # Method 2: Redirect the request to a different server
    #if flow.request.pretty_host.endswith("/account/me/user"):
     # flow.request.url = "file:///Users/xxx/Documents/workspace/xxxxxAutomation/ios/features/mock_data_test/user.json"

      mock_user = "file:///Users/xxx/Documents/workspace/xxxxxAutomation/ios/features/mock_data_test/user.json"

# Note: my real url is : https://www.abcd.net/account/me/user

      if flow.request.pretty_host.endswith("xxxx.net/account/me/user"):
             resp = HTTPResponse(
                 "HTTP/1.1", 200, b"OK",
                 Headers(Content_Type="application/json"),
                 str(mock_user)
             )
             flow.reply.send(resp)

```

```auto
Getting Error:
flow.reply.send(resp)\nAttributeError: Reply instance has no attribute 'send'

```

instead of mitmproxy.models I am using libmproxy.models because mitmproxy.models results into an error.

I tried everything under request pretty host and url but still it is not working.

Please let me know, how can I achieve it.

---

<div class="post-metadata">

**Author:** ![shrikantkaramkar](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@shrikantkaramkar](https://discourse.mitmproxy.org/u/shrikantkaramkar)\
**Post date:** [July 20, 2016, 2:27pm UTC](https://discourse.mitmproxy.org/t/request-redirect-not-working-for-using-static-data/90/2 "2016-07-20T14:27:53Z")

</div>

I got it working.Example:

```auto
from libmproxy.models import HTTPResponse
from netlib.http import Headers

import json

def request(context, flow):

      with open('/path_to_file/mock_data_test/user.json') as data_file:
          data = json.load(data_file)
          print(json.dumps(data, sort_keys=True, indent=4))
          new_data = json.dumps(data)

      if flow.request.pretty_url.endswith("/url/user"):
         resp = HTTPResponse(
                                 "HTTP/1.1",
                                 200,
                                 "OK",
                                 Headers(Content_Type="application/json"),
                                 str(new_data)
         )

         flow.reply(resp)

```
