2017-01-23 81 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:")