我正在尝试使用 mitmproxy 记录每个 http 站点,但我的内联脚本给出了这个错误 TypeError: request() missing 1 required positional argument: 'flow' 这是预览我的代码。我的代理设置正确,httplogs.txt 文件与内联脚本位于同一目录中,但我不明白此函数有什么问题。
import sys
def request(context,flow):
f = open('httplogs.txt', 'a+')
f.write(flow.request.url + '\n')
f.close()
最佳答案
假设您使用的是更新版(2017 年 1 月)
tl;dr
从方法签名中删除上下文
7 个月前,mitmproxy 从response 方法中删除了context:
https://github.com/mitmproxy/mitmproxy/commit/c048ae1d5b652ad4778917e624ace217e1ecfd91
更新后的示例脚本在这里:
https://github.com/mitmproxy/mitmproxy/blob/1.0.x/examples/simple/add_header.py
def response(flow):
flow.response.headers["newheader"] = "foo"
关于python - 使用 mitmproxy 内联脚本记录所有 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41798971/