TAGS :Viewed: 3 - Published at: a few seconds ago

[ Django non-rel createsuperuser fails due to non-ascii characters ]

I am tring to create a new superuser on my django app engine project, In order to gain access to the built in admin functions. Every time when I run

python manage.py createsuperuser

I get an error saying " "'NoneType' object has no attribute 'mkstemp'" "

I tried to reinstall django python and the app engine sdk, with no luck, I moved the project into a directory that has no non-ascii letters in it's path as I feared it might be the cause of the problem, again, with no luck... I am out of ideas...

This is the complete traceback of the exception thrown:

Traceback (most recent call last):
File "manage.py", line 11, in <module>
File "C:\empeeric\pickadeal\django\core\management\__init__.py", line 438, in execute_manager
File "C:\empeeric\pickadeal\django\core\management\__init__.py", line 379, in execute
File "C:\empeeric\pickadeal\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\empeeric\pickadeal\django\core\management\base.py", line 220, in execute
output = self.handle(*args, **options)
File "C:\empeeric\pickadeal\django\contrib\auth\management\commands\createsuperuser.py", line 72, in handle
File "C:\empeeric\pickadeal\django\db\models\manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
File "C:\empeeric\pickadeal\django\db\models\query.py", line 346, in get
num = len(clone)
File "C:\empeeric\pickadeal\django\db\models\query.py", line 82, in __len__
self._result_cache = list(self.iterator())
File "C:\empeeric\pickadeal\django\db\models\query.py", line 275, in iterator
for row in compiler.results_iter():
File "C:\empeeric\pickadeal\djangotoolbox\db\basecompiler.py", line 229, in results_iter
for entity in self.build_query(fields).fetch(low_mark, high_mark):
File "C:\empeeric\pickadeal\djangotoolbox\db\basecompiler.py", line 289, in build_query
File "C:\empeeric\pickadeal\djangotoolbox\db\basecompiler.py", line 74, in add_filters
File "C:\empeeric\pickadeal\djangotoolbox\db\basecompiler.py", line 78, in add_filters
self.add_filter(column, lookup_type, self._negated, db_type, value)
File "C:\empeeric\pickadeal\djangoappengine\db\compiler.py", line 61, in _func
return func(*args, **kwargs)
File "C:\empeeric\pickadeal\djangoappengine\db\compiler.py", line 271, in add_filter
self._add_filter(column, op, db_type, value)
File "C:\empeeric\pickadeal\djangoappengine\db\compiler.py", line 279, in _add_filter
value = self.convert_value_for_db(db_type, value)
File "C:\empeeric\pickadeal\djangotoolbox\db\basecompiler.py", line 209, in convert_value_for_db
return self.compiler.convert_value_for_db(db_type, value)
File "C:\empeeric\pickadeal\djangoappengine\db\compiler.py", line 445, in convert_value_for_db
value = value.decode('utf-8') if isinstance(value, str) else value
File "C:\hp\bin\Python\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-4: unsupported Unicode code range
Exception exceptions.AttributeError: "'NoneType' object has no attribute 'mkstemp'" in <bound method DatastoreFileStub.__del__ of <google.appengine.api.datasto
e_file_stub.DatastoreFileStub object at 0x02277890>> ignored


Answer 1

Since you haven't passed any arguments to it, createsuperuser.py uses the Python getpass module to get a default user name. (Line 59, createsuperuser.py):

        # Try to determine the current system user's username to use as a default.
        default_username = getpass.getuser().replace(' ', '').lower()
    except (ImportError, KeyError):
        # 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).
        default_username = ''

Seems to me getpass.getuser() isn't returning a string that can be decoded by Python's UTF-8 decoder. My guess is the default user name on your Windows installation is encoded in some older, non-unicode 8-bit encoding. Perhaps you have some accented characters in your default Windows username, for e.g.?

This bug apparently has been reported on the main branch for Django, and so perhaps one of the workarounds documented here may do the trick for you: