You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用extract-msg库提取Outlook邮件时因特殊字符引发UnicodeDecodeError的解决方法咨询

extract-msg库提取Outlook邮件时因特殊字符引发UnicodeDecodeError的解决方法咨询

我使用extract_msg库的extract_message来提取Outlook邮件内容,大部分场景下都能正常工作,但最近处理一份Outlook文件时突然触发了错误。排查后发现问题出在邮件内容里的特殊字符,比如â–ª这类字符导致了解码异常。想请教各位,有没有办法让程序忽略这类特殊字符,避免报错并顺利完成邮件提取?

以下是相关代码片段和完整错误回溯信息:

msg = extract_msg.Message(email)

错误日志:

2024-12-11 16:02:00,865 - ERROR : [message_base.py:97 - __init__] Critical error accessing the body. File opened but accessing the body will throw an exception.
Traceback (most recent call last):
  File "C:\Users\xxxxx\miniconda\envs\spy_3_10\lib\cmd.py", line 214, in onecmd
    func = getattr(self, 'do_' + cmd)
AttributeError: 'InterruptiblePdb' object has no attribute 'do_msg'. Did you mean: 'do_s'?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\xxxxx\miniconda\envs\spy_3_10\lib\site-packages\extract_msg\msg_classes\message_base.py", line 94, in __init__
    self.body
  File "C:\Users\xxxxx\miniconda\envs\spy_3_10\lib\functools.py", line 981, in __get__
    val = self.func(instance)
  File "C:\Users\xxxxx\miniconda\envs\spy_3_10\lib\site-packages\extract_msg\msg_classes\message_base.py", line 944, in body
    if (body := self.getStringStream('__substg1.0_1000')) is not None:
  File "C:\Users\xxxxx\miniconda\envs\spy_3_10\lib\site-packages\extract_msg\msg_classes\msg.py", line 738, in getStringStream
    return None if tmp is None else tmp.decode(self.stringEncoding)
  File "C:\Users\xxxxx\miniconda\envs\spy_3_10\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 2279: character maps to <undefined>

备注:内容来源于stack exchange,提问作者user1769197

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:48:01