我遇到了这个问题:即使我在views.py的顶部添加了# -*- coding: utf-8 -*-
,我也会收到UnicodeDecodeError
。我如何在观点中处理这些德语变音符号ü,ö,ä
?我正在尝试在其内容中发送带有德语变音符号的电子邮件。
请帮我解决这个问题。我希望德国变音符号以其原始形式正确显示。我可以像ä
那样写ae
,但这是我想要避免的。
错误:
位于/ location-save /的 UnicodeDecodeError
('ascii','kannst Du \ n diese Location einsehen.M \ xc3 \ xb6glichkeiten zur Bearbeitung der Locations werden bald zur Verfuegung stehen。\ n \ n Herzliche Gruesse,\ n Dein LocateYourDate Team',55,56,'ordinal not not在范围(128)')
无法编码/解码的字符串是:en。 Mglic
答案 0 :(得分:2)
你得到一个UnicodeDecodeError,因为你试图将非ascii字节串(在Python 2中称为str
而在Python 3中称为bytes
)转换为Unicode字符串(称为{{1}在Python 2中和Python 3中的Unicode
,而没有指定它的编码。
如果没有完整的追溯,那就不可能更有帮助了。
我猜你正在使用Python 2,你做了类似的事情:
str
你可能想要的是:
mystring = 'Det här är ju helt omöjligt'
注意u'',将其变成Unicode字符串。