I just updated an environment to Django 1.4. On syncdb's first run I get the following error:
我刚刚将一个环境更新为Django 1.4。在syncdb的第一次运行时,我收到以下错误:
TypeError: decode() argument 1 must be string, not None
This error is triggered by django/contrib/auth/management/init
:
此错误由django / contrib / auth / management / init触发:
try:
return getpass.getuser().decode(locale.getdefaultlocale()[1])
except (ImportError, KeyError, UnicodeDecodeError):
# KeyError will be raised by os.getpwuid() (called by getuser())
# if there is no corresponding entry in the /etc/passwd file
# (a very restricted chroot environment, for example).
# UnicodeDecodeError - preventive treatment for non-latin Windows.
return u''
getdefaultlocale
returns None
getdefaultlocale返回None
After reading this Django ticket, I tried the unofficial patch which worked, however I think I could do better by figuring out what happends..
在阅读了这张Django门票后,我尝试了非官方的补丁,但是我认为通过弄清楚发生了什么,我可以做得更好。
So I opened a python command line, and tried:
所以我打开了一个python命令行,并尝试:
import os
print os.getenv()
None
os.getenv.__doc__
"Get an environment variable, return None if it doesn't exist.\n The optional second argument can specify an alternate default."
Could I solve this issue within OSX itself? Tips are welcome
我可以在OSX中解决这个问题吗?欢迎提示
1 个解决方案
#1
13
The immediate resolution for this, assuming you are using bash as your shell:
假设您使用bash作为shell,立即解决此问题:
$ export LC_ALL=en_US.UTF-8
$ export LC_ALL = en_US.UTF-8
$ export LANG=en_US.UTF-8
$ export LANG = en_US.UTF-8
This will set your locale for that session, and syncdb will work. You can add this to your profile and make it permanent for your shells.
这将为该会话设置您的语言环境,syncdb将起作用。您可以将其添加到您的个人资料中,并使其永久保存。
You can use the locale
command to see the current settings, and locale -a
to see what locales are available to you. en_US.UTF-8
is a generic safe one, but you may have other preferences.
您可以使用locale命令查看当前设置,使用locale -a查看可用的语言环境。 en_US.UTF-8是一个通用安全的,但您可能有其他偏好。
#1
13
The immediate resolution for this, assuming you are using bash as your shell:
假设您使用bash作为shell,立即解决此问题:
$ export LC_ALL=en_US.UTF-8
$ export LC_ALL = en_US.UTF-8
$ export LANG=en_US.UTF-8
$ export LANG = en_US.UTF-8
This will set your locale for that session, and syncdb will work. You can add this to your profile and make it permanent for your shells.
这将为该会话设置您的语言环境,syncdb将起作用。您可以将其添加到您的个人资料中,并使其永久保存。
You can use the locale
command to see the current settings, and locale -a
to see what locales are available to you. en_US.UTF-8
is a generic safe one, but you may have other preferences.
您可以使用locale命令查看当前设置,使用locale -a查看可用的语言环境。 en_US.UTF-8是一个通用安全的,但您可能有其他偏好。