【发布时间】:2020-11-25 22:04:22
【问题描述】:
我正在尝试使用 awdeoroi 邮件合并。在 html 模板中,我在段落标签中有法语编码的字符。 当我执行邮件时,我有编码错误:
UnicodeDecodeError : 'utf-8' codec can't decode byte 0xf4 in position 81: invalid continuation byte
如何对这些段落进行编码,以便它们在 python 中得到很好的处理?
TO: {{email}}
SUBJECT: Testing mailmerge
FROM: My Self <myself@mydomain.com>
Content-Type: text/html
<html>
<body>
<p>Hi, {{name}},</p>
<p>Your number is {{number}}.</p>
<p>Sent by <a href="https://github.com/awdeorio/mailmerge">Here is the paragraph. Ce texte est en francais. <b>Accentué<b>. L'ideal</a></p>
</body>
</html>
【问题讨论】:
-
您的“邮件”似乎不是 UTF-8。发现它是什么编码,然后相应地威胁它。但在电子邮件中,最好使用 html 实体,而不是直接字符。
-
检测字节串的字符编码,看看chardet
标签: python html python-3.x character-encoding mailmerge