Closed jimklo closed 9 years ago
From the top of my head, I'd say it's because you're feeding it a decoded unicode stream instead of raw bytes. Try to give it a simple open(self.filename, 'rb')
.
(I'm sounding uncertain because I never actually tried to give a unicode buffer to YAJL as an input :-) )
Yep. That was it. Thanks.
It's odd open(filename) just works in P2 but not in P3. Defaults must have changed.
The default mode of open()
in both Py2 and Py3 is text. However in Py2 text is represented by byte strings and that's what you get from .read()
, no matter in which mode the file was opened. The mode in Py2 pretty much only controls how line breaks are treated on different platforms. Py3 switched to representing text with unicode and now you bytes
type from open('...', 'rb')
and str
type (which is unicode) from open('...', 'r')
. In other words, in Py3 the mode actually mean what it says :-).
Not quite sure how to debug, but tried installing from github master. Python 3.4.2 w/ libyajl 2.1.0 on OS X 10.10
sample2.json contains
when I execute my script I get the following error:
I stuck pdb on line 95 in yajl2.py, this is what I discovered:
From the surface it looks like \n isn't getting ignored or stripped, however your Travis tests for Python 3.4 seem to be passing.
FWIW switching from codecs.open to open makes no difference, same error.
If I use Python 2 it all works, however my script has some Python 3 dependencies.