【问题标题】:How to decode this representation of a unicode string in Python? [duplicate]如何在 Python 中解码 unicode 字符串的这种表示形式? [复制]
【发布时间】:2012-09-13 16:57:28
【问题描述】:

我正在使用imaplib 从 Gmail 中获取电子邮件的主题,其中一些主题如下所示:

=?utf-8?Q?12_=D7=A1=D7=91=D7=99=D7=97?=

如何将此表示解码为普通的 Unicode 文本?

提前致谢!

【问题讨论】:

    标签: python utf-8 gmail-imap


    【解决方案1】:

    您的字符串使用Quoted-printable MIME 标头格式进行编码。 email.header module 为您处理这个问题:

    >>> from email.header import decode_header
    >>> for part in decode_header('=?utf-8?Q?12_=D7=A1=D7=91=D7=99=D7=97?='):
    ...     print(str(*part))
    12 סביח
    

    【讨论】:

    • 天哪,谢谢!过去一个月我一直在寻找这个答案。优秀!谢谢
    猜你喜欢
    • 1970-01-01
    • 2020-07-23
    • 2011-06-22
    • 2018-09-21
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多