python - 'utf- 8' can' t 解码位置 0 : invalid start byte 中的字节 0xc0

标签 python django

我尝试执行 Django 的 createsuperuser 并收到以下错误。在syncdb数据库为空并以“utf-8”编码之前。我正在使用 pymysql。

D:\Python27\site\mysite>python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site

You just installed Django's auth system, which means you don't have any superuse
rs defined.
Would you like to create one now? (yes/no): yes
Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "D:\python27\lib\site-packages\django\core\management\__init__.py", line
438, in execute_manager
    utility.execute()
  File "D:\python27\lib\site-packages\django\core\management\__init__.py", line
379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\python27\lib\site-packages\django\core\management\base.py", line 191,
 in run_from_argv
    self.execute(*args, **options.__dict__)
  File "D:\python27\lib\site-packages\django\core\management\base.py", line 220,
 in execute
    output = self.handle(*args, **options)
  File "D:\python27\lib\site-packages\django\core\management\base.py", line 351,
 in handle
    return self.handle_noargs(**options)
  File "D:\python27\lib\site-packages\django\core\management\commands\syncdb.py"
, line 109, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "D:\python27\lib\site-packages\django\core\management\sql.py", line 190,
in emit_post_sync_signal
    interactive=interactive, db=db)
  File "D:\python27\lib\site-packages\django\dispatch\dispatcher.py", line 172,
in send
    response = receiver(signal=self, sender=sender, **named)
  File "D:\python27\lib\site-packages\django\contrib\auth\management\__init__.py
", line 70, in create_superuser
    call_command("createsuperuser", interactive=True)
  File "D:\python27\lib\site-packages\django\core\management\__init__.py", line
166, in call_command
    return klass.execute(*args, **defaults)
  File "D:\python27\lib\site-packages\django\core\management\base.py", line 220,
 in execute
    output = self.handle(*args, **options)
  File "D:\python27\lib\site-packages\django\contrib\auth\management\commands\cr
eatesuperuser.py", line 72, in handle
    User.objects.get(username=default_username)
  File "D:\python27\lib\site-packages\django\db\models\manager.py", line 132, in
 get
    return self.get_query_set().get(*args, **kwargs)
  File "D:\python27\lib\site-packages\django\db\models\query.py", line 344, in g
et
    num = len(clone)
  File "D:\python27\lib\site-packages\django\db\models\query.py", line 82, in __
len__
    self._result_cache = list(self.iterator())
  File "D:\python27\lib\site-packages\django\db\models\query.py", line 273, in i
terator
    for row in compiler.results_iter():
  File "D:\python27\lib\site-packages\django\db\models\sql\compiler.py", line 68
0, in results_iter
    for rows in self.execute_sql(MULTI):
  File "D:\python27\lib\site-packages\django\db\models\sql\compiler.py", line 73
5, in execute_sql
    cursor.execute(sql, params)
  File "D:\python27\lib\site-packages\django\db\backends\util.py", line 34, in e
xecute
    return self.cursor.execute(sql, params)
  File "D:\python27\lib\site-packages\django\db\backends\mysql\base.py", line 86
, in execute
    return self.cursor.execute(query, args)
  File "build\bdist.win32\egg\pymysql\cursors.py", line 96, in execute
  File "build\bdist.win32\egg\pymysql\connections.py", line 575, in escape
  File "build\bdist.win32\egg\pymysql\converters.py", line 22, in escape_item
  File "build\bdist.win32\egg\pymysql\converters.py", line 45, in escape_sequenc
e
  File "build\bdist.win32\egg\pymysql\converters.py", line 27, in escape_item
  File "D:\python27\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc0 in position 0: invalid s
tart byte

最佳答案

代码为C0的字节是invalid UTF-8 编码文本。我不知道该文本来自何处,但它要么是无效的 UTF-8,要么您的代码错误地尝试将其视为 UTF-8。

关于python - 'utf- 8' can' t 解码位置 0 : invalid start byte 中的字节 0xc0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5942031/

相关文章:

python - 共享非连续访问 Numpy 数组

python - django 模板中的可变图像

Python - 将函数调用拆分为函数和参数

python - uWSGI 重置 PythonHome

python - Pandas :将列的值分配到字典值设置的限制

Python、uWSGI、NGINX、FLASK 适用于 WiFi,不适用于蜂窝网络

python - django 多对多通过

python - django 模型字段的不同 setter 和 getter

python - 如何防止 Sentry 捕获一些未捕获的异常事件和日志消息?

python - 使用 Django Rest Framework 序列化器创建外键关系的方法