带有compilemessages django转换程序的UnicodeDecodeError

时间:2014-05-28 11:51:32

标签: django

我收到此错误

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

虽然我想使用

编译.po文件
python django.admin.py manage.py compilemessages

这是我的django.po文件:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-05-28 11:39+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: blog/forms.py:6
msgid "name"
msgstr ""

#: blog/forms.py:7
msgid "e-mail"
msgstr ""

#: blog/forms.py:8
msgid "comment"
msgstr ""

#: blog/Template/post.html:34
msgid "send"
msgstr ""

回溯:

 python2.7 manage.py compilemessages
processing file django.po in /home/arash/Lab/django/arash_blog/conf/locale/fa_IR/LC_MESSAGES
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.7/site-packages/django/core/management/commands/compilemessages.py", line 71, in handle
    compile_messages(self.stdout, locale=locale)
  File "/usr/lib/python2.7/site-packages/django/core/management/commands/compilemessages.py", line 42, in compile_messages
    if not f.endswith('.po'):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128)

1 个答案:

答案 0 :(得分:0)

看看你的追溯,显然,你的.po文件没有错误:

File "/usr/lib/python2.7/site-packages/django/core/management/commands/compilemessages.py", line 42, in compile_messages
    if not f.endswith('.po'):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128)

看到if not

您的仓库中有一个(至少)一个文件,很可能是一个Python文件,其中包含非ASCII字符。您所要做的就是找到它并在顶部添加:

#coding:utf-8

或者该文件使用的任何编码。由于您使用的是Linux,因此很可能确实会utf-8,但这可能取决于您的编辑。


如果您无法找到所述文件,只需打开/usr/lib/python2.7/site-packages/django/core/management/commands/compilemessages.py,然后在第42行if子句之前添加print f行。

然后运行命令。你应该看到追溯上方的罪魁祸首。

一旦找到它,只需删除该打印声明。