mitmdump 不适用于 openpyxl(python 包)

mitmdump not working with openpyxl (python package)

我正在尝试使用 Python3 的 mitmdump 和 openpyxl 包将请求和响应存储到 excel。

在执行命令时 "mitmdump -s body_respXL.py" 我遇到以下错误。

Loading script: body_respXL.py Addon error: Traceback (most recent call last): File "/usr/local/Cellar/mitmproxy/3.0.3/libexec/lib/python3.6/site-packages/mitmproxy/addonmanager.py", line 67, in safecall yield File "/usr/local/Cellar/mitmproxy/3.0.3/libexec/lib/python3.6/site-packages/mitmproxy/addons/script.py", line 77, in tick ns = load_script(self.fullpath) File "/usr/local/Cellar/mitmproxy/3.0.3/libexec/lib/python3.6/site-packages/mitmproxy/addons/script.py", line 30, in load_script loader.exec_module(m) File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "body_respXL.py", line 1, in import openpyxl ModuleNotFoundError: No module named 'openpyxl'

Ignored options: {'web_static_viewer': '', 'view_order_reversed': False, 'console_focus_follow': False, 'web_open_browser': True, 'view_order': 'time', 'web_iface': '127.0.0.1', 'web_debug': False, 'web_port': 8081} Proxy server listening at http://*:8080

但是当我这样做时 "pip3 freeze" 我看到软件包已安装。

下面是python代码-

import openpyxl

def response(flow):
    if "insert" in flow.request.pretty_url:
        wb = openpyxl.load_workbook("Workbook1.xlsx")
        ws = wb.worksheets[0]
        if flow.request.content:
            ws.cell(row = ws.max_row + 1, column = 1, value=flow.request.content)
        if flow.response.content:
            ws.cell(row = ws.max_row, column = 2, value=flow.response.content)
        wb.save("Workbook1.xlsx")

请帮帮我,谢谢。

找到解决方案。

mitm 将在安装时创建自己的 Python 环境,在 mitm 环境中安装软件包后问题得到解决。

在我的例子中,源文件在以下位置创建: /usr/local/Cellar/mitmproxy/3.0.3/libexec/bin/activate