2

I am using this command to dump data

py -Xutf8 manage.py dumpdata app.ModelName --indent 4 --format=json --output app/fixtures/data.json

which works perfectly fine. However when I try to run the command in script

management.call_command(
    "dumpdata",
    indent=4,
    format="json",
    output=os.path.join(path, "app//fixtures//data.json"),
    verbosity=1,
)

It ends up with this error:

django.core.management.base.CommandError: Unable to serialize database: 'charmap' codec can't encode characters in position 1-2: character maps to <undefined>

I have tried something like this yet it still doesn't work. Any solutions to this?

1 Answers1

0

Look at it in a hex editor (free ones are available online, or use Linux vim, etc.) and make sure the MSb is 0. "smart quotes" (left & right leaning, 0x93) in particular show up in automatically in Microsoft stuff (Notepad will not remove these chars). Use ASCII (a sub-set of UTF-8--first row in encoding table here: https://en.wikipedia.org/wiki/UTF-8#Encoding (note also that not all bit patterns are legal)) only.

This might help too, but it goes beyond what we are talking about here: https://www.charset.org/charsets/iso-8859-1

Andrew
  • 1
  • 4
  • 19