Reputation: 3
I'm running Debian wheezy and have installed mitmproxy from system packages, and pushbullet.py (https://github.com/randomchars/pushbullet.py) using pip, ie.
apt-get install mitmproxy
pip install pushbullet.py
Pushbullet works when I import from python cmdline, like so:
$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pushbullet import PushBullet
>>> pb=PushBullet(myapikeyremoved)
>>>
However, when I try to import the pushbullet module from within a mitmproxy script, it is unable to find the module.
$ echo "from pushbullet import PushBullet" > mypb.py
$ mitmproxy -s mypb.py
Script load error: Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/libmproxy/script.py", line 48, in load
execfile(path, ns, ns)
File "mypb.py", line 1, in <module>
from pushbullet import PushBullet
ImportError: No module named pushbullet
Now, pip has installed pushbullet.py and its dependencies python-magic, requests, backports.ssl-match-hostname into /usr/local/lib/python2.7/dist-packages/. It seems that cmdline python has found the pip-installed packages, but mitmproxy is not able to for some reason.
So, I've tried to add the path via PYTHONPATH or via system path, but I think I must still be doing something wrong.
$ cat mypb.py
import sys
sys.path.append('/usr/local/lib/python2.7/dist-packages')
from pushbullet import PushBullet
pb=PushBullet(myapikeyremoved)
$ mitmproxy -s mypb.py
Script load error: Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/libmproxy/script.py", line 48, in load execfile(path, ns, ns)
File "mypb.py", line 4, in <module>
pb=PushBullet(myapikeyremoved)
File "/usr/local/lib/python2.7/dist-packages/pushbullet/pushbullet.py", line 26, in __init__
self.refresh()
File "/usr/local/lib/python2.7/dist-packages/pushbullet/pushbullet.py", line 223, in refresh
self._load_devices()
File "/usr/local/lib/python2.7/dist-packages/pushbullet/pushbullet.py", line 32, in _load_devices
resp_dict = resp.json()
TypeError: 'dict' object is not callable
Can anyone shed light on why everything works in via cmdline python and fails when loaded as a script from within mitmproxy, and how to fix it? How should modules installed via pip be loaded?
Upvotes: 0
Views: 1173
Reputation: 3
Thanks to Christian Rapp's comments, I looked further into why mitmproxy's libmproxy was being loaded from /usr/lib/python2.6. It turns out that (at least on the debian wheezy package), the mitmproxy shebang explicitly specifies python2.6:
$ head -1 /usr/bin/mitmproxy
#! /usr/bin/python2.6
That explains why mitmproxy fails to find the pushbullet module; it is looking in the 2.6 directories instead.
I guess that the "TypeError: 'dict' object is not callable" error when I explicitly loaded the module is also because pushbullet relied on some feature of python 2.7.
Upvotes: 0