我有 html 文件来读取解析等,它是在 unicode 上编码的(我用记事本看到的)但是当我尝试时
infile = open("path", "r")
infile.read()
Run Code Online (Sandbox Code Playgroud)
它失败了,我遇到了著名的错误:
UnicodeEncodeError: 'charmap' 编解码器无法对位置 xx 中的字符进行编码:字符映射到未定义
因此,为了进行测试,我尝试将文件的包含复制粘贴到一个新文件中并将其保存在 utf-8 中,然后尝试使用这样的编解码器打开它:
inFile = codecs.open("path", "r", encoding="utf-8")
outputStream = inFile.read()
Run Code Online (Sandbox Code Playgroud)
但我收到此错误消息:
UnicodeEncodeError : 'charmap' 编解码器无法对位置 0 的字符 u'\ufeff' 进行编码:字符映射到未定义
我真的不明白,因为我是用 utf8 创建的这个文件。