Menu

#1355 UnicodeDecodeError in Py3.2 when opening JSON file

open
nobody
None
5
2011-07-20
2011-07-20
Anonymous
No

Trying to open a JSON-file with non-ASCII characters results in a UnicodeDecodeError. The code runs fine outside Eclipse.

Setup:

Python 3.2
Eclipse 3.7 + PyDev 2.2.1
MacOS 10.6.8

pydev debugger: starting
Traceback (most recent call last):
File "/Applications/eclipse/plugins/org.python.pydev.debug_2.2.1.2011071313/pysrc/pydevd.py", line 1256, in <module>
debugger.run(setup['file'], None, None)
File "/Applications/eclipse/plugins/org.python.pydev.debug_2.2.1.2011071313/pysrc/pydevd.py", line 1009, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "/Applications/eclipse/plugins/org.python.pydev.debug_2.2.1.2011071313/pysrc/_pydev_execfile.py", line 37, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the script

[...]

File "/Users/hmg/econ/struct-ret/src/data_management/fj11_replication/readers.py", line 44, in get_contents
return json.load(open(file_path))
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/json/__init__.py", line 259, in load
return loads(fp.read(),
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcf in position 254: ordinal not in range(128)

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.