首页 > 解决方案 > Python提取味精库:'gbk'编解码器无法解码字节:非法多字节序列

问题描述

错误详情

描述 我有一个提取电子邮件文件的应用程序。如果邮件文件包含 gbk 编解码器(中文字符),模块方法 Message(path to file) 会抛出异常。

代码片段

from extract_msg import Message
try:
     msg = Message(vault_path)
except Exception as e:
     return action_result.set_status(APP_ERROR, "Failed to parse message. Error: {0}".format(str(e)))

来自库调用的错误消息

“消息”:“无法解析消息。错误:'gbk'编解码器无法解码位置 34-35 中的字节:非法多字节序列”

追溯:

File "/opt/folder/dependencies/extract_msg/message.py", line 95, in __init__#012    self.body#012  
File "/opt/folder/dependencies/extract_msg/message.py", line 460, in body#012    self._body = self._getStringStream('__substg1.0_1000')#012 
File "/opt/folder/dependencies/extract_msg/message.py", line 166, in _getStringStream#012    return None if tmp is None else
tmp.decode(self.stringEncoding)#012UnicodeDecodeError: 'gbk' codec can't decode bytes in position 34-35: illegal multibyte sequence

我不允许共享 .msg 文件。该文件有gbk编解码器(汉字)

标签: python-2.7

解决方案


推荐阅读