When I attempt to run the script below in Eclipse(PyDev):
import subprocess
subprocess.call("/usr/local/bin/mitmdump")
An error is returned:
Traceback (most recent call last):
File "/usr/local/bin/mitmdump", line 19, in <module>
from libmproxy import proxy, dump, cmdline
File "/Library/Python/2.7/site-packages/libmproxy/proxy.py", line 22, in <module>
import shutil, tempfile, threading
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 34, in <module>
from random import Random as _Random
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
If I run the same script from the bash, it works fine. What gives?
$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call("/usr/local/bin/mitmdump")
127.0.0.1 GET http://google.com/
There seems to be a related problem with Ubuntu Python ImportError cannot import urandom Since Ubuntu 12.04 upgrade but my environment is OSX.
To properly diagnose that, do the following:
Edit /usr/local/bin/mitmdump, and make:
And then check if what you’re seeing is actually what you expected… (you can do those same prints in the command line to when the exception is not raised and check what’s the difference and then, probably, update your PYTHONPATH inside Eclipse/PyDev).