3

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.

asked Feb 4, 2019 at 15:49
4
  • This probably has to do with the encoding used by your terminal and / or Python. Search for "UnicodeEncodeError terminal" and see if anything there helps you. Commented Feb 5, 2019 at 0:47
  • 2
    In your shell, try setting the PYTHONIOENCODING environment variable before running the createsuperuser command. So run: export PYTHONIOENCODING="UTF-8"; python3.6 manage.py createsuperuser Commented Feb 5, 2019 at 9:06
  • @WillKeeling, you right ! It was due to the env var PYTHONIOENCODING. Commented Feb 5, 2019 at 9:27
  • @Rekoc - great, will add an answer. Commented Feb 5, 2019 at 10:57

2 Answers 2

11

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
answered Feb 5, 2019 at 11:02
Sign up to request clarification or add additional context in comments.

Comments

1

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

answered Feb 4, 2019 at 16:31

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.