isagalaev / ijson

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

TypeError when trying to use CFFI backend #55

Closed quezak closed 8 years ago

quezak commented 8 years ago

When trying to use the CFFI backend as instructed in the readme, I get the following error:

$ ./test.py  <<< "{}"
Traceback (most recent call last):
  File "./test.py", line 7, in <module>
    for prefix, event, value in parser:
  File "/usr/lib64/python3.4/site-packages/ijson/common.py", line 65, in parse
    for event, value in basic_events:
  File "/usr/lib64/python3.4/site-packages/ijson/backends/yajl2_cffi.py", line 218, in basic_parse
    yajl_parse(handle, buffer)
  File "/usr/lib64/python3.4/site-packages/ijson/backends/yajl2_cffi.py", line 179, in yajl_parse
    result = yajl.yajl_parse(handle, buffer, len(buffer))
TypeError: initializer for ctype 'unsigned char *' must be a bytes or list or tuple, not str

It seems to happen in all cases, a trivial example:

#!/usr/bin/env python3
import ijson.backends.yajl2_cffi as ijson
import sys

parser = ijson.parse(sys.stdin)
for prefix, event, value in parser:
    print(prefix, event, value)

The same code, when the import is changed to just import ijson, works just fine:

$ ./test.py <<< "{}"
 start_map None
 end_map None

OS: Gentoo Linux ijson version: 2.3 yajl version: 2.1.0 cffi version: 1.8.3 python version: 3.4.3

quezak commented 8 years ago

Additional info: I also get an error using ijson.backends.yajl2:

Traceback (most recent call last):
  File "./test.py", line 7, in <module>
    for prefix, event, value in parser:
  File "/usr/lib64/python3.4/site-packages/ijson/common.py", line 65, in parse
    for event, value in basic_events:
  File "/usr/lib64/python3.4/site-packages/ijson/backends/yajl2.py", line 94, in basic_parse
    raise exception(error.decode('utf-8'))
ijson.common.IncompleteJSONError: lexical error: invalid char in json text.
                                      {                     (right here) ------^

Trying to use ijson.backends.yajl results in ijson.backends.YAJLImportError: YAJL version 1.x required, found 2.1.0, but that's expected. Using ijson.backends.python works fine.

By the way: seeing the above results, do I guess correctly that python is the backend used by default?

quezak commented 8 years ago

Sorry, I forgot to check closed issues before. This is a duplicate of #54