gpt4 book ai didi

python - 调用 'createsuperuser' 时引发 UnicodeEncodeError

转载 作者:行者123 更新时间:2023-11-29 12:40:07 24 4
gpt4 key购买 nike

我正在尝试使用 PostGreSQL 数据库在我的服务器上部署我的 Django 应用程序(2.1.5 和 Python 3.6.6)。我像往常一样执行了“makemigrations”和“迁移”,然后无法使用命令“createsuperuser”创建 super 用户:

[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)

我在谷歌上找到添加:

# -*- Coding: utf-8 -*-

在文件的顶部但它不起作用,与变量 DEFAULT_CHARSET ( https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-DEFAULT_CHARSET ) 的结果相同。我的 PostGreSQL 数据库要求使用 utf-8 编码。

最佳答案

这可能是因为用于标准输入的编码不支持在 input() 提示符下输入的字符。

您可以尝试使用 PYTHONIOENCODING 将编码显式设置为 UTF-8运行 createsuperuser 命令之前的环境变量:

export PYTHONIOENCODING="UTF-8"; python3.6 manage.py createsuperuser

关于python - 调用 'createsuperuser' 时引发 UnicodeEncodeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54519674/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com