When trying to debug Python code that has non-ascii unicode symbols (even in comments), an encoding problem pops up:
UnicodeDecodeError: 'ascii' codec can't decode byte ...
Traceback (most recent call last):
File "/eclipse/plugins/org.python.pydev_2.7.1.2012100913/pysrc/pydevd.py", line 1397, in <module>
debugger.run(setup['file'], None, None)
File "/eclipse/plugins/org.python.pydev_2.7.1.2012100913/pysrc/pydevd.py", line 1090, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "/eclipse/plugins/org.python.pydev_2.7.1.2012100913/pysrc/_pydev_execfile.py", line 34, in execfile
contents = stream.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 0xd0 in position 93: ordinal not in range(128)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What worked for me (sorry, I'm still learning Python) is adding into _pydev_execfile.py(32)
import sys
before the default open(file), which seems to force the proper system default encoding
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "(deprecated) Please use https://www.brainwy.com/tracker/PyDev/"
Sample Python file with UTF-8 comment that breaks the debugger
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "(deprecated) Please use https://www.brainwy.com/tracker/PyDev/"
Traceback (most recent call last):
File "/eclipse/plugins/org.python.pydev_2.7.1.2012100913/pysrc/pydevd.py", line 1397, in <module>
debugger.run(setup['file'], None, None)
File "/eclipse/plugins/org.python.pydev_2.7.1.2012100913/pysrc/pydevd.py", line 1090, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "/eclipse/plugins/org.python.pydev_2.7.1.2012100913/pysrc/_pydev_execfile.py", line 34, in execfile
contents = stream.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 0xd0 in position 93: ordinal not in range(128)
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "(deprecated) Please use https://www.brainwy.com/tracker/PyDev/"
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "(deprecated) Please use https://www.brainwy.com/tracker/PyDev/"
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "(deprecated) Please use https://www.brainwy.com/tracker/PyDev/"
In _pydev_execfile.py the final stream = open(file) uses ascii by default for some reason
The problem can be circumvented by adding
#encoding=utf-8
at the beginning of every file that uses utf-8 symbols inside
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "(deprecated) Please use https://www.brainwy.com/tracker/PyDev/"
What worked for me (sorry, I'm still learning Python) is adding into _pydev_execfile.py(32)
import sys
before the default open(file), which seems to force the proper system default encoding
if encoding:
stream = open(file, encoding=encoding)
else:
import sys
stream = open(file)
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "(deprecated) Please use https://www.brainwy.com/tracker/PyDev/"
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "(deprecated) Please use https://www.brainwy.com/tracker/PyDev/"
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "(deprecated) Please use https://www.brainwy.com/tracker/PyDev/"
##Sorry, stream = open(file, encoding=sys.getdefaultencoding()) of course
Last edit: Anonymous 2016-01-25