1

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

5
  • Does your text editor actually use UTF-8? Commented Apr 1, 2013 at 4:59
  • @DietrichEpp, i am using aptana, i dont know about this, can i see this somewhere? Commented 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. Commented 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. Commented Apr 1, 2013 at 5:10
  • @LennartRegebro, :)). no problem. i will post the traceback also now Commented Apr 1, 2013 at 5:11

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks, please see my error message update in the question. what should i do now?
@doniyor: Well, you need to understand how Unicode works in Python, to be honest. So you need to read the documentation and maybe some helpful blogposts. Start with these two: regebro.wordpress.com/2011/03/23/… farmdev.com/talks/unicode
very nice. great help. honestly, i am very lazy to read about encodings :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.