Search code examples
pythonmitmproxy

Logging all http request with mitmproxy inline script


I'm trying to log every http site with mitmproxy but my in-line script is giving this error TypeError: request() missing 1 required positional argument: 'flow' Here is a preview of my code. I do have my proxy set up correctly and the httplogs.txt file on the same directory as the in-line script but I don't understand what is wrong in this function.

import sys

def request(context,flow):
    f = open('httplogs.txt', 'a+')
    f.write(flow.request.url + '\n')
    f.close()

Solution

  • Assuming you're on an updated (Jan 2017) version

    tl;dr

    remove context from method signature


    7 months ago mitmproxy removed context from the response method:

    https://github.com/mitmproxy/mitmproxy/commit/c048ae1d5b652ad4778917e624ace217e1ecfd91 Da commit

    So the updated example script is here:

    https://github.com/mitmproxy/mitmproxy/blob/1.0.x/examples/simple/add_header.py

    def response(flow):
        flow.response.headers["newheader"] = "foo"