1

I'm using Powershell and django web framework for python. This web framework has a utility for dumping data from your database python manage.py dumpdata. When you call this command, you will get via stdout all your database entries serialized as json (no problems with this output, everything is ok):

[
    {
        "model": "user.user",
        "pk": "007a0078-f538-4c01-9a77-694cdd6b142f",
        "fields": {
            "name": "César"
        }
    },
...
]

So you easily can use the redirection operator > and put the output in a file python manage.py dumpdata > myfile.json. My issue comes after doing that (redirecting the output to a file), if I have letters with latin accents they are replaced for weird characters:

{
        "model": "user.user",
        "pk": "fa35df0c-5ce4-4ff0-a4c6-ee25e32930e7",
        "fields": {
            "name": "C¾sar"
        }
},

I've also tried to set powershell and python sys stdin and out encoding to utf-8 with

-python manage.py dumpdata | out-file myfile.json -encoding utf8

-import sys; sys.stdout.reconfigure(encoding='utf-8')

But still facing the same problem.

  • Hello, I have updated my question with a more descriptive information. Also I've already tried that solutions, even powershell says its encoding is UTF-8. –  Apr 27 '21 at 14:12
  • I don't know python at all sadly. – marsze Apr 27 '21 at 15:24

1 Answers1

0

Seems this problem is related to Powershell rather than Python, since its output it's well encoded.

I found a partial solution for this specific case, using the python standard library for creating the desired json file instead the redirection operator >