isagalaev / ijson

Iterative JSON parser with Pythonic interface
http://pypi.python.org/pypi/ijson/
Other
615 stars 134 forks source link

isjon raises AttributeError when importing yajl2 backends on RHEL6 #66

Closed wfscheper closed 5 years ago

wfscheper commented 7 years ago

Attemping to import either the yajl2_cffi or yajl2 backends on RHEL6 throws an AttributeError instead of ImportError.

Quick reproduction case:

try:
    import ijson.backends.yajl2_cffi as ijson
except ImportError:
    try:
        import ijson.backends.yajl2 as ijson
    except ImportError:
        import ijson

Instead of importing the pure-python backend, this results in the following stacktraces depending on whether cffi is installed or not:

With cffi:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/root/tmp/lib/python2.6/site-packages/ijson/backends/yajl2_cffi.py", line 65, in <module>
    yajl = backends.find_yajl_cffi(ffi, 2)
  File "/root/tmp/lib/python2.6/site-packages/ijson/backends/__init__.py", line 41, in find_yajl_cffi
    require_version(yajl.yajl_version(), required)
  File "/root/tmp/lib/python2.6/site-packages/cffi/api.py", line 866, in __getattr__
    make_accessor(name)
  File "/root/tmp/lib/python2.6/site-packages/cffi/api.py", line 862, in make_accessor
    accessors[name](name)
  File "/root/tmp/lib/python2.6/site-packages/cffi/api.py", line 792, in accessor_function
    value = backendlib.load_function(BType, name)
AttributeError: function/symbol 'yajl_version' not found in library 'libyajl.so.1': /usr/lib64/libyajl.so.1: undefined symbol: yajl_version

Without cffi:

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/root/tmp/lib/python2.6/site-packages/ijson/backends/yajl2.py", line 12, in <module>
    yajl = backends.find_yajl_ctypes(2)
  File "/root/tmp/lib/python2.6/site-packages/ijson/backends/__init__.py", line 29, in find_yajl_ctypes
    require_version(yajl.yajl_version(), required)
  File "/usr/lib64/python2.6/ctypes/__init__.py", line 366, in __getattr__
    func = self.__getitem__(name)
  File "/usr/lib64/python2.6/ctypes/__init__.py", line 371, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /usr/lib64/libyajl.so.1: undefined symbol: yajl_version

Fix is to wrap require_version(yajl.yajl_version(), required) at lines 29 and 41 with a try/except to catch the AttributeError and raise an ImportError. I can open a pull request if you'd like.

Edit: clean up stacktrace formatting.

jmcken8 commented 6 years ago

+1

SilasK commented 5 years ago

What would be the solution to this error? installing ijson or is it not possible to use sourmash on a RHEL6?

rtobar commented 5 years ago

Solved in ICRAR/ijson, will be published in the next PyPI release.

wfscheper commented 5 years ago

@rtobar, awesome!

rtobar commented 5 years ago

Note that in CentOS 6 you will still get an error trying to import the yajl2-related backends, as the yajl version installed in those systems (unless you installed one yourself) is 1.0.9.