Menu

#1555 (solution proposed) ascii codec used in debugger by default

open
debugger (210)
3
2013-02-11
2013-02-11
Anonymous
No

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 ...

Discussion

  • Anonymous

    Anonymous - 2013-02-11

    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)

     
  • Anonymous

    Anonymous - 2013-02-11

    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

     
  • Anonymous

    Anonymous - 2013-02-11

    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)

     
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.