首页 > 解决方案 > 运行 python runserver --nothreading -noreload 时出错

问题描述

/home/saumen/.local/lib/python2.7/site-packages/django/core/management/__init__.py:316: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if subcommand == 'runserver' and '--noreload' not in self.argv:
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 61, in execute
    super(Command, self).execute(*args, **options)
  File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/saumen/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 86, in handle
    'or address:port pair.' % options['addrport'])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

运行 python runserver --nothreading -noreload 时出现错误。我该怎么办?我已经安装了 mysqlclient 和必要的 python 库。

标签: pythondjangopython-2.7

解决方案


首先编辑您的答案并将代码放在第 86 行...由于 UnicodeDecodeError 而发生错误:

这可能对您有用:(注意:your_string 是您要解码的内容)

your_String.encode('ascii', 'ignore').decode('utf-8')

对于更具体的问题:

str(options['addrport']).encode('ascii', 'ignore').decode('utf-8')

推荐阅读