2017-01-23 84 views
2

我正在尝试使用mitmproxy记录每个http站点,但是我的内联脚本发出此错误TypeError:request()缺少1所需的位置参数:'flow'这里是我的代码预览。我的代理设置正确,httplogs.txt文件与内联脚本位于同一目录,但我不明白这个函数中有什么问题。使用mitmproxy内联脚本记录所有http请求

import sys 

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

回答

2

假设你在更新(一月至2017)版本

TL;博士

从方法签名删除context


7个月前mitmproxy删除方面响应方法:

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

所以更新的示例脚本是在这里:

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

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

谢谢。我拉我的头发 – Katz

+0

听起来类似的经验,我的:) – user3041539

0

谢谢,修好了!

这是我的日志请求&响应头更新片段:

def response(flow): 
    print("") 
    print("="*50) 
    #print("FOR: " + flow.request.url) 
    print(flow.request.method + " " + flow.request.path + " " + flow.request.http_version) 

    print("-"*50 + "request headers:") 
    for k, v in flow.request.headers.items(): 
     print("%-20s: %s" % (k.upper(), v)) 

    print("-"*50 + "response headers:") 
    for k, v in flow.response.headers.items(): 
     print("%-20s: %s" % (k.upper(), v)) 
     print("-"*50 + "request headers:")