diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
index 9966849..83cb47b 100644
--- a/django/contrib/auth/management/__init__.py
+++ b/django/contrib/auth/management/__init__.py
@@ -83,14 +83,17 @@ def get_system_username():
     :returns: The username as a unicode string, or an empty string if the
         username could not be determined.
     """
-    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''
+    default_locale = locale.getdefaultlocale()[1] 
+    if default_locale:
+        try:
+            return getpass.getuser().decode(default_locale)
+        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.
+            pass
+    return u''
 
 
 def get_default_username(check_db=True):
diff --git a/django/contrib/auth/tests/basic.py b/django/contrib/auth/tests/basic.py
index 6a3b656..fbee587 100644
--- a/django/contrib/auth/tests/basic.py
+++ b/django/contrib/auth/tests/basic.py
@@ -1,7 +1,10 @@
+import locale
+from StringIO import StringIO
+
 from django.test import TestCase
 from django.contrib.auth.models import User, AnonymousUser
 from django.core.management import call_command
-from StringIO import StringIO
+from django.contrib.auth.management.commands import createsuperuser
 
 class BasicTestCase(TestCase):
     def test_user(self):
@@ -93,3 +96,41 @@ class BasicTestCase(TestCase):
         self.assertEqual(u.email, 'joe@somewhere.org')
         self.assertFalse(u.has_usable_password())
 
+    def test_createsuperuser_nolocale(self):
+        """ Check that createsuperuser does not break when no locale is set. 
+            See ticket #16017.
+        """
+
+        try:
+            old_getdefaultlocale = locale.getdefaultlocale
+            old_getpass = createsuperuser.getpass
+
+            # Temporarily remove locale information
+            locale.getdefaultlocale = lambda: (None, None)
+
+            # Temporarily replace getpass to allow interactive code to be used
+            # non-interactively
+            class mock_getpass: pass
+            mock_getpass.getpass = staticmethod(lambda p=None: "nopasswd")
+            createsuperuser.getpass = mock_getpass
+
+            # Call the command in this new environment
+            new_io = StringIO()
+            call_command("createsuperuser",
+                interactive=True,
+                username="nolocale@somewhere.org",
+                email="nolocale@somewhere.org",
+                stdout=new_io
+            )
+        except TypeError, e:
+            self.fail("createsuperuser failed when without locale information")
+
+        finally:
+            # Re-apply locale and getpass information
+            createsuperuser.getpass = old_getpass
+            locale.getdefaultlocale = old_getdefaultlocale
+
+        # If we were successful, a user would have been created
+        u = User.objects.get(username="nolocale@somewhere.org")
+        self.assertEqual(u.email, 'nolocale@somewhere.org')
+
