【问题标题】:AWS sns email notification receiving utf-8 characters like =C3=A8AWS sns 电子邮件通知接收 utf-8 字符,例如 =C3=A8
【发布时间】:2018-01-20 03:31:40
【问题描述】:

我在 django 应用程序中收到来自主题转发电子邮件的 sns 通知。 Message.content 中存在的请求正文 json 包含奇怪的 utf-8 格式(即:“=C3=A8”代表“è”)和一些“=”。

我正在尝试在加载之前对其进行解析:

body = request.body.decode('utf-8')

body_unicode = unicode(body)
js = json.loads(body_unicode.replace('\n', ''))

但我做不到。子字符串“=C3=A8”仍在body_unicode 中。

【问题讨论】:

  • decode 将字节转换为 unicode 字符串。为什么你unicode 是解码后的字符串的结果? =C3=A8 是什么? è的url转义码是%C3%A8

标签: python utf-8 amazon-sns


【解决方案1】:

这些是引号可打印字符,用于电子邮件。您正在查看的内容可以转换为python中的普通字符串,如下所示

Python 3.6.1 (default, Apr  4 2017, 09:40:21)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import quopri
>>> data = quopri.decodestring("=C3=A8")
>>> data
b'\xc3\xa8'
>>> data.decode("utf-8")
'è'
>>>

更多详情请参考How to understand the equal sign '=' symbol in IMAP email text?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    • 2021-04-02
    • 2015-04-27
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    相关资源
    最近更新 更多