当前位置: 首页 > 工具软件 > Komodo IDE > 使用案例 >

Komodo IDE 7.0.2 Debug UTF-8 Python 文档的Bug

颜华池
2023-12-01

        Komodo IDE 7.0.2 调试UTF-8 Python 文档时,会抛出如下异常:

Traceback (most recent call last):
  File "C:\Program Files\ActiveState Komodo IDE 7\lib\support\dbgp\python3lib\dbgp\client.py", line 2260, in runMain
    self.dbg.runfile(debug_args[0], debug_args)
  File "C:\Program Files\ActiveState Komodo IDE 7\lib\support\dbgp\python3lib\dbgp\client.py", line 1847, in runfile
    h_execfile(file, args, module=main, tracer=self)
  File "C:\Program Files\ActiveState Komodo IDE 7\lib\support\dbgp\python3lib\dbgp\client.py", line 661, in __init__
    contents = fd.read()
UnicodeDecodeError: 'gbk' codec can't decode bytes in position 2-3: illegal multibyte sequence
        显然是字符编码问题,找到报错的文件client.py,第 661 行,再看看上下几行,如下:

        try:
            exec("import site\n\n", globals, locals)
            del globals['site']
            if _is_py3:
                globals['__file__'] = file
                encoding = self._get_file_encoding(file)
                fd = open(file)
                try:
                    contents = fd.read()
                finally:
                    fd.close()
         这里的open默认把文件当作ASCII来处理,这里需要加上文档本身的编码格式,可以看到这里已经获取到文件的encoding,那么把 “fd = open(file)”  改成 “fd = open(file, encoding=encoding)” 即可解决问题。修改后保存再调试就OK。


 类似资料: