I am trying to deploy my Django application (2.1.5 with Python 3.6.6) on my server with a PostGreSQL database. I did a 'makemigrations' and 'migrate' as usual and then I can't create a super user with the command 'createsuperuser':
[alex@web574 myproject]$ python3.6 manage.py createsuperuser
Nom d'utilisateur (leave blank to use 'alex'):
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/contrib/auth/management/commands/createsuperuser.py", line 60, in execute
return super().execute(*args, **options)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/contrib/auth/management/commands/createsuperuser.py", line 139, in handle
input_value = self.get_input_data(field, message)
File "/home/alex/webapps/global_hse_project/lib/python3.6/Django-2.1.5-py3.6.egg/django/contrib/auth/management/commands/createsuperuser.py", line 194, in get_input_data
raw_value = input(message)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 8: ordinal not in range(128)
I found on Google to add:
# -*- Coding: utf-8 -*-
at the top of the file but it doesn't work, same result with the variable DEFAULT_CHARSET (https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-DEFAULT_CHARSET). My PostGreSQL database are asking for utf-8 encoding.
2 Answers 2
This may be caused by the fact that encoding used for the stdin does not support the characters being typed in at the input() prompt.
You can try explicitly setting the encoding to UTF-8 using the PYTHONIOENCODING environment variable before you run the createsuperuser command:
export PYTHONIOENCODING="UTF-8"; python3.6 manage.py createsuperuser
Comments
I think it is the same problem as here: previous post You have to add
# -*- coding: utf-8 -*-
in the start of each file to include the right encoding
Comments
Explore related questions
See similar questions with these tags.
PYTHONIOENCODINGenvironment variable before running thecreatesuperusercommand. So run:export PYTHONIOENCODING="UTF-8"; python3.6 manage.py createsuperuser