Skip to content

I use Pyinstaller to freeze my script into a Unix file, and execute the Unix file. Installation of the certificate fails. #4794

@xzhacker123

Description

@xzhacker123

Problem Description

I want to freeze my custom mitmproxy service into a Unix file for others to use. When I typed mitm.it in the browser of an Android device to install the certificate, the following problem occurred:

--- Logging error ---
Traceback (most recent call last):
  File "flask/app.py", line 2447, in wsgi_app
  File "flask/app.py", line 1952, in full_dispatch_request
  File "flask/app.py", line 1821, in handle_user_exception
  File "flask/_compat.py", line 39, in reraise
  File "flask/app.py", line 1950, in full_dispatch_request
  File "flask/app.py", line 1936, in dispatch_request
  File "mitmproxy/addons/onboardingapp/__init__.py", line 14, in index
  File "flask/templating.py", line 138, in render_template
  File "jinja2/environment.py", line 930, in get_or_select_template
  File "jinja2/environment.py", line 883, in get_template
  File "jinja2/environment.py", line 857, in _load_template
  File "jinja2/loaders.py", line 115, in load
  File "flask/templating.py", line 60, in get_source
  File "flask/templating.py", line 89, in _get_source_fast
jinja2.exceptions.TemplateNotFound: index.html

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "logging/__init__.py", line 1084, in emit
TypeError: a bytes-like object is required, not 'str'
Call stack:
  File "threading.py", line 890, in _bootstrap
  File "threading.py", line 932, in _bootstrap_inner
  File "threading.py", line 870, in run
  File "concurrent/futures/thread.py", line 80, in _worker
  File "concurrent/futures/thread.py", line 57, in run
  File "asgiref/sync.py", line 462, in thread_handler
  File "asgiref/wsgi.py", line 140, in run_wsgi_app
  File "flask/app.py", line 2464, in __call__
  File "flask/app.py", line 2450, in wsgi_app
  File "flask/app.py", line 1871, in handle_exception
  File "flask/app.py", line 1891, in log_exception
  File "logging/__init__.py", line 1463, in error
  File "logging/__init__.py", line 1577, in _log
  File "logging/__init__.py", line 1587, in handle
  File "logging/__init__.py", line 1649, in callHandlers
  File "logging/__init__.py", line 950, in handle
  File "logging/__init__.py", line 1089, in emit
Message: 'Exception on / [GET]'
Arguments: ()
192.168.xxx.xxx:46364: GET http://mitm.it/

This is my script mitm_async.py

class MetaHttp:
    pass

def main():
    myaddon = MetaHttp()
    # prot = sys.argv[1]
    prot = '8888'
    opts = options.Options(listen_port=int(prot))
    pconf = proxy.config.ProxyConfig(opts)
    m = dump.DumpMaster(opts)
    m.server = proxy.server.ProxyServer(pconf)
    m.addons.add(myaddon)

    try:
        m.run()
    except KeyboardInterrupt:
        m.shutdown()


if __name__ == "__main__":
    main()

This is my freeze command:

pyi-makespec -F --name mitm mitm_async.py

Steps to reproduce the behavior:

  1. freeze the script
  2. Execute Unix file
  3. Android device connection proxy
  4. Device browser input: mitm.it

System Information

Paste the output of "mitmproxy --version" here.

Mitmproxy: 6.0.2
Python: 3.8.0
OpenSSL: OpenSSL 1.1.1i 8 Dec 2020
Platform: macOS-10.15.7-x86_64-i386-64bit

It looks like I didn't pack the static files in when I freeze the program, and I executed the script without error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions