Keep encountering `Script error` when modifying response

Hi,

I’m new to Python either mitmproxy, just keep encountering script error when using the below sample script:

def response(flow):
    flow.response.headers["newheader"] = "foo"
Steps to reproduce the problem:
  1. Install mitmproxy 0.17.1 from prebuild binary mitmproxy-0.17.1-osx.tar.gz
  2. On testing mitmdump with the simplest sample script - examples/add_header.py (same result with mitmproxy)
  3. Try request a page through browser
  4. The console threw an error for every connection made:
Script error:
response() takes exactly 1 argument (2 given)
What is the expected behavior?

newheader header should be added in response’s header

Any other comments? What have you tried so far?

Try with both mitmproxy & mitm => same result
Try with other sample script examples/modify_response_body.py => same result.


Mitmproxy Version: 0.71.1
Operating System: OSX 10.10.5
Python Version: 2.7


Any advice is appreciated.
Thanks

Turned verbose mode on and update the detail console log:

127.0.0.1 POST https://discourse.mitmproxy.org/message-bus/5256e5c778fe453982aa95e8b1662bc6/poll?dlp=t HTTP/2.0
 << 200  28B
127.0.0.1:63695: request
  -> Request(POST /api/channels.history?_x_id=438d3288-1473148708.043)
127.0.0.1:63659: HTTP2 Event from client
  -> <StreamReset stream_id:3, error_code:8, remote_reset:True>
127.0.0.1:63659: HTTP2 Event from client
  -> <RequestReceived stream_id:7, headers:[(u':method', u'POST'), (u':authority', u'discourse.mitmproxy.org'), (u':scheme', u'https'), (u':path', u'/message-bus/67762f7bce08445baac6de98e3d0c271/poll'), (u'content-length', u'359'), (u'origin', u'https://discourse.mitmproxy.org'), (u'x-csrf-token', u'__CENSORED__'), (u'user-agent', u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'), (u'content-type', u'application/x-www-form-urlencoded; charset=UTF-8'), (u'x-silence-logger', u'true'), (u'accept', u'application/json, text/javascript, */*; q=0.01'), (u'dont-chunk', u'true'), (u'x-requested-with', u'XMLHttpRequest'), (u'referer', u'https://discourse.mitmproxy.org/t/mitmproxy-not-working-with-urls-which-have-under-scores/156/2'), (u'accept-encoding', u'gzip, deflate, br'), (u'accept-language', u'en-US,en;q=0.8,vi;q=0.6'), (u'cookie', u'__utma=30234659.1379679291.1472721903.1473135494.1473146934.3'), (u'cookie', u'__utmb=30234659.1.10.1473146934'), (u'cookie', u'__utmc=30234659'), (u'cookie', u'__utmz=30234659.1473135494.2.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)'), (u'cookie', u'__CENSORED__')]>
127.0.0.1:63659: HTTP2 Event from client
  -> <PriorityUpdated stream_id:7, weight:183, depends_on:0, exclusive:True>
127.0.0.1:63659: HTTP2 Event from client
  -> <DataReceived stream_id:7, flow_controlled_length:359, data:2532466e65773d3739262532466c61746573743d>
127.0.0.1:63659: HTTP2 Event from client
  -> <StreamEnded stream_id:7>
127.0.0.1:63659: request
  -> Request(POST discourse.mitmproxy.org:443/message-bus/67762f7bce08445baac6de98e3d0c271/poll)
127.0.0.1:63695: response
  -> Response(200 OK, application/json; charset=utf-8, 2.95kB)
Script error:
response() takes exactly 1 argument (2 given)

Hi!

It looks like your inline script is from master, but you are using the latest stable release from mitmproxy. Can you please select the right tag on GitHub and try again?

1 Like

OMG how stupid I am.
It’s working now.

Thanks dude :slight_smile: