我正在使用此命令转储数据
py -Xutf8 manage.py dumpdata app.ModelName --indent 4 --format=json --output app/fixtures/data.json它工作得非常好。但是,当我尝试在脚本中运行该命令时
management.call_command(
"dumpdata",
indent=4,
format="json",
output=os.path.join(path, "app//fixtures//data.json"),
verbosity=1,
)它以这个错误结束:
django.core.management.base.CommandError: Unable to serialize database: 'charmap' codec can't encode characters in position 1-2: character maps to <undefined>我已经尝试过像this这样的东西,但它仍然不起作用。有什么解决方案吗?
发布于 2021-08-01 01:43:06
在十六进制编辑器中查看它(免费的在线可用,或使用Linux vim等)并确保MSb为0。特别是“智能引号”(左右倾斜,0x93)会自动出现在微软的东西中(记事本不会删除这些字符)。仅使用ASCII码(UTF-8的子集--编码表中的第一行:https://en.wikipedia.org/wiki/UTF-8#Encoding (还要注意,并非所有位模式都是合法的))。
这可能也有帮助,但它超出了我们在这里讨论的范围:https://www.charset.org/charsets/iso-8859-1
https://stackoverflow.com/questions/68606838
复制相似问题