How to run mitmproxy in Heroku?

I am using mitmproxy with Python. Python version is 3.11.0 and mitmproxy version is 10.2.0. When I install mitmproxy, it installed other dependencies such as

mitmproxy-macos==0.5.1
mitmproxy_rs==0.5.1
urwid-mitmproxy==2.1.2.1

When I run in my local environment, it works fine but when I tried to run in Heroku, it returns an error. The error looks like this

Traceback (most recent call last):
  File "/app/.heroku/python/bin/mitmdump", line 5, in 
     from mitmproxy.tools.main import mitmdump 
ModuleNotFoundError: No module name 'mitmproxy.tools'

When I check build log in Heroku, the package is installed properly with same version that I have in my local environment.

After running Python main File, I am running mitmproxy as follows:

subprocess.Popen(['mitmdump', '-s', 'filepath']) 
1 Answers

To run mitmproxy in Heroku, you can try the following steps:

  1. Ensure that all dependencies required by mitmproxy are correctly installed in your Heroku environment. Double-check the versions and dependencies to match your local setup.

  2. Instead of directly calling mitmdump using subprocess, you can try calling it using the Python module. You may need to modify your script to import the necessary modules correctly.

  3. Make sure the PATH environment variable in Heroku includes the directory where mitmproxy is installed.

  4. Check the Heroku logs for any additional error messages or hints on why the module 'mitmproxy.tools' is not being found. This can provide more insight into the issue.

By following these steps, you should be able to run mitmproxy successfully in Heroku.