3

I have this django website translating from english to german from the locale/lc_messages/django.po and django.mo files. But, when i try to translate the words which are in german letters like ü and ä, it gives me the error

'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128) 

As far as I can think, django is trying to decode the unicode characters through ASCII which is not possible. But how do i fix this ? Where should I make the setting for django to decode through utf-8 and not through ASCII. Or let me know if I am wrong.

traceback:

DjangoUnicodeDecodeError at /de/ 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128). You passed in <django.utils.functional.__proxy__ object at 0x0000000005EB40B8> (<class 'django.utils.functional.__proxy__'>) Request Method: GET Request URL: http://127.0.0.1:8000/de/ Django Version: 1.10.1 Exception Type: DjangoUnicodeDecodeError Exception Value: 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128). You passed in <django.utils.functional.__proxy__ object at 0x0000000005EB40B8> (<class 'django.utils.functional.__proxy__'>) Exception Location: C:\Users\deybala1\AppData\Local\Continuum\Anaconda2\lib\site-packages\django\utils\encoding.py in force_text, line 88 Python Executable: C:\Users\deybala1\AppData\Local\Continuum\Anaconda2\python.exe Python Version: 2.7.11 Python Path: ['C:\\Users\\deybala1\\Documents\\pe-locator', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\pyexcel-0.2.3-py2.7.egg', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\django_registration-2.1.2-py2.7.egg', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\django_http_proxy-0.4.3-py2.7.egg', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\django_redis-4.4.4-py2.7.egg', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\django_redis_sessions-0.5.6-py2.7.egg', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\python27.zip', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\DLLs', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\plat-win', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\lib-tk', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2', 'c:\\users\\deybala1\\appdata\\local\\continuum\\anaconda2\\lib\\site-packages\\sphinx-1.3.5-py2.7.egg', 'c:\\users\\deybala1\\appdata\\local\\continuum\\anaconda2\\lib\\site-packages\\setuptools-20.3-py2.7.egg', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\win32', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\win32\\lib', 'C:\\Users\\deybala1\\AppData\\Local\\Continuum\\Anaconda2\\lib\\site-packages\\Pythonwin'] Server time: Fr, 28 Okt 2016 04:58:23 -0500 Unicode error hint The string that could not be encoded/decoded was: ne pr��fung 

This is my msgid and msgstr from django.po

#: .\app\templates\app\layout.html:47 msgid "Take Exam" msgstr "Eine prüfung anlegen" 
3
  • 1
    Please show the full traceback. Commented Oct 28, 2016 at 9:57
  • Do you have # coding: utf-8 on first line of your file? Commented Oct 28, 2016 at 10:25
  • where do you want me to have that ? I tried putting it over all the py files in my project. But is it due to that ? I think the error is while decoding the utf 8 to ascii. Commented Oct 28, 2016 at 11:11

2 Answers 2

6

Found the solution, had to put the header in all .po files at top.

"MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" 

Thanks for helping guys. It is better solution to use poedit for working with .po files

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

Comments

0

Could there be a problem in the po file (it is python 2.7)? You can try:

msgstr u"Eine prüfung anlegen" 

1 Comment

I tried msgstr "u'Eine prüfung anlegen'". But doesn't work. same error. And yes it is python 2.7

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.