richard-better / pushbullet.py

A python client for http://pushbullet.com
MIT License
575 stars 110 forks source link

Improve fallback when python is unable to import magic module #94

Closed gpailler closed 6 years ago

gpailler commented 8 years ago

I use a motioneyeos distribution on a rPi and installed pushbullet.py using easy_install on it

When I try to import pushbullet.py from a custom script, I face the following exception

Traceback (most recent call last):
  File "eventstart.py", line 7, in <module>
    from pushbullet import Pushbullet
  File "/usr/lib/python2.7/site-packages/pushbullet.py-0.10.0-py2.7.egg/pushbullet/__init__.py", line 2, in <module>
    from .pushbullet import Pushbullet
  File "/usr/lib/python2.7/site-packages/pushbullet.py-0.10.0-py2.7.egg/pushbullet/pushbullet.py", line 8, in <module>
    from .filetype import get_file_type
  File "/usr/lib/python2.7/site-packages/pushbullet.py-0.10.0-py2.7.egg/pushbullet/filetype.py", line 12, in <module>
    import magic
  File "build/bdist.linux-armv6l/egg/magic.py", line 150, in <module>
  File "/usr/lib/python2.7/ctypes/util.py", line 242, in find_library
  File "/usr/lib/python2.7/ctypes/util.py", line 235, in _findSoname_ldconfig
IOError: [Errno 10] No child processes

I don't know why magic import fails but it's a very small distribution based on BuildRoot and probably a component required by magic is missing. I extended the except fallback to IOError to fix the issue:

In filetypes.py

try:
    import magic
except (ImportError, IOError):
    import mimetypes
    get_file_type = _guess_file_type
kovacsbalu commented 7 years ago

Hi @gpailler, as I can see the main problem is the missing ldconfig. Are you sure, this code fix your problem?