i am having this issue: even if i added # -*- coding: utf-8 -*- on the top of my views.py, i am getting UnicodeDecodeError. how can i handle those german umlauts ü,ö,ä in my views? i am trying to send emails with german umlauts in its content.
please help me with this issue. i want that german umlauts are shown correctly in its original form. i can write ä like ae, but this is what i want to avoid.
i googled a lot, but couldnot find anything that helped me
ERROR:
UnicodeDecodeError at /location-save/
('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 in range(128)')
The string that could not be encoded/decoded was: en. M��glic
-
Does your text editor actually use UTF-8?Dietrich Epp– Dietrich Epp2013年04月01日 04:59:12 +00:00Commented Apr 1, 2013 at 4:59
-
@DietrichEpp, i am using aptana, i dont know about this, can i see this somewhere?doniyor– doniyor2013年04月01日 05:00:11 +00:00Commented Apr 1, 2013 at 5:00
-
UnicodeDecodeError has nothing to do with you using non-ascii characters in the file, but rather what you are doing with them. You need to show a complete error message as this can be caused by an infinite amount of different things.Lennart Regebro– Lennart Regebro2013年04月01日 05:04:16 +00:00Commented Apr 1, 2013 at 5:04
-
Sorry, I was unclear. When I said error message, I meant traceback. It's 6am and I have had no coffee. My bad.Lennart Regebro– Lennart Regebro2013年04月01日 05:10:26 +00:00Commented Apr 1, 2013 at 5:10
-
@LennartRegebro, :)). no problem. i will post the traceback also nowdoniyor– doniyor2013年04月01日 05:11:13 +00:00Commented Apr 1, 2013 at 5:11
1 Answer 1
You get a UnicodeDecodeError because you are trying to convert a non-ascii string of bytes (called str in Python 2 and bytes in Python 3) to a Unicode string (called Unicode in Python 2 and str in Python 3) without specifying it's encoding.
It's not possible to be more helpful than that without a full traceback.
I will guess that you are using Python 2, and you did something like this:
mystring = 'Det här är ju helt omöjligt'
What you probably want is this:
mystring = u'Det här är ju helt omöjligt'
Note the u'', making it into a Unicode string.