pythonmitmproxy

mitmdump not working with openpyxl (python package)


I'm trying to store request and responses into excel using mitmdump and openpyxl package of Python3.

While executing the command "mitmdump -s body_respXL.py" i'm getting below error.

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

but when i do "pip3 freeze" i'm seeing the package as installed.

Below is the python code -

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

Please help me out, Thanks.


Solution

  • Got solution.

    mitm will have it's own Python environment created at the time of installation, problem got resolved after i installed package with in mitm environment.

    In my case the source file created at below location : /usr/local/Cellar/mitmproxy/3.0.3/libexec/bin/activate