簡體   English   中英

使用mitmproxy內聯腳本記錄所有http請求

[英]Logging all http request with mitmproxy inline script

我正在嘗試使用mitmproxy記錄每個http站點,但是我的內聯腳本給出了此錯誤TypeError:request()缺少1個必需的位置參數:'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;博士

從方法簽名中刪除context


7個月前mitmproxy從響應方法中刪除了上下文

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"

謝謝,已經解決了!

這是我更新的用於記錄請求和響應標頭的代碼段:

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:")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM