Python os.getenv on OSX (Django 1.4)

I just updated the Django 1.4 environment. When I start syncdb for the first time, I get the following error:

TypeError: decode() argument 1 must be string, not None 

This error is triggered using 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

After reading this Django ticket, I tried an unofficial patch that worked, but I think I could do better by figuring out what was going on.

So, I opened the python command line and tried:

 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." 

Can I solve this problem in OSX itself? Tips are welcome

+6
source share
1 answer

Immediate permission for this if you use bash as a shell:

$ export LC_ALL=en_US.UTF-8

$ export LANG=en_US.UTF-8

This will set your language for this session and syncdb will work. You can add this to your profile and make it permanent for your shells.

You can use the locale command to view the current settings and locale -a to find out which locales are available to you. en_US.UTF-8 is general safe, but you may have other settings.

+13
source

Source: https://habr.com/ru/post/911730/


All Articles