UnicodeDecodeError:"utf-8"编解码器无法解码位置0的字节0xff [英] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0

查看:93
本文介绍了UnicodeDecodeError:"utf-8"编解码器无法解码位置0的字节0xff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我试图将django文件和sqlite3数据库文件迁移到MySQL数据,我遇到了这样的错误.

  1. I tried to migrate the django file and the sqlite3 database file to MySQL data, and I encountered such an error.

创建数据库:创建数据库mysite_db默认charset = utf8mb4默认整理utf8mb4_unicode_ci;

create database: create database mysite_db default charset=utf8mb4 default collate utf8mb4_unicode_ci;

db_sqlite3中的数据迁移:python manage.py dumpdata>data.json

Data migration in db_sqlite3: python manage.py dumpdata > data.json

输入mysql:python manage.py loaddata data.json

input mysql: python manage.py loaddata data.json


File "C:\blog_env\lib\site-packages\django\core\management\commands\loaddata.py", line 113, in loaddata
    self.load_label(fixture_label)
  File "C:\blog_env\lib\site-packages\django\core\management\commands\loaddata.py", line 168, in load_label
    for obj in objects:
  File "C:\blog_env\lib\site-packages\django\core\serializers\json.py", line 66, in Deserializer
    stream_or_string = stream_or_string.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
(blog_env) PS C:\blog_env\mysite>

推荐答案

我最近遇到了同样的问题...这是我的解决方案:

I had the same problem recently... here's my solution:

确认"file_path"的编码格式:

Confirm the encoding format of 'file_path':

  1. 下载并使用记事本++打开文件
  2. 检查右下角;在那里,您可以查看文件是否以兼容格式编码,或者是否具有字节顺序标记或BOM表符号
  3. 如果其中任何一个为真,则只需另存为"正确/所需的格式即可.

您应该对上述情况满意.

You should be fine with the above.

这篇关于UnicodeDecodeError:"utf-8"编解码器无法解码位置0的字节0xff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆