运行从stdin读取的Python程序时,出现以下错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 320: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
注意:错误发生在antlr内部,并且该行看起来像:
self.strdata = unicode(data)
Run Code Online (Sandbox Code Playgroud)
由于我不想修改源代码,我想传递一些可接受的内容.
输入代码如下所示:
#!/usr/bin/python
import sys
import codecs
import antlr3
import antlr3.tree
from LatexLexer import LatexLexer
from LatexParser import LatexParser
char_stream = antlr3.ANTLRInputStream(codecs.getreader("utf8")(sys.stdin))
lexer = LatexLexer(char_stream)
tokens = antlr3.CommonTokenStream(lexer)
parser = LatexParser(tokens)
r = parser.document()
Run Code Online (Sandbox Code Playgroud)