Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python os.getenv on OSX (Django 1.4)

I just updated an environment to Django 1.4. On syncdb's first run I get the following error:

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

This error is triggered by 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 the unofficial patch which worked, however I think I could do better by figuring out what happends..

So I opened a 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."

Could I solve this issue within OSX itself? Tips are welcome

like image 478
Hedde van der Heide Avatar asked Mar 27 '12 08:03

Hedde van der Heide


1 Answers

The immediate resolution for this, assuming you are using bash as your shell:

$ export LC_ALL=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.

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.

like image 71
Burhan Khalid Avatar answered Nov 05 '22 10:11

Burhan Khalid