32đź‘Ť
What worked for me is following these steps:
- Open the file in regular notepad
- Select save as
- Select encoding "UTF-8" (Not "UTF-8 (With BOM)")
- Save the file.
Now you can use loaddata.
However, this only works for files that are small enough for notepad to open.
7đź‘Ť
0xff
in position 0 looks like the start of a little-endian UTF-16 byte order marker to me. Notepad’s “Unicode” save mode is little-endian UTF-16, so that makes sense if you saved your json from Notepad after creating it. Notepad will keep the byte order marker even in utf-8, which could plausibly cause loaddata to fail to parse it.
If you don’t have your un-edited json still handy, you’ll need to remove the BOM – personally I’d use emacs, but another answer suggested this stand-alone Windows .exe:
4đź‘Ť
On windows, if you run your standard dumpdata command with -Xutf8 it has always solved this problem for me:
python -Xutf8 manage.py dumpdata app.mymodel > app/fixtures/mymodel.json
Here is an article for reference:
https://dev.to/methane/python-use-utf-8-mode-on-windows-212i
3đź‘Ť
After good research, I got the solution.
In my case, datadump.json
file was having the issue.
- Simply Open the file in notepad format
- Click on save as option
- Go to encoding section below & Click on "UTF-8"
- Save the file.
Now you can try running the command. You are good to go 🙂
For your reference, I have attached images below.
- Zip File downloaded from ReactJs/Axios is corrupted
- How to access current user in Django class based view
- Default value for Django choices field
2đź‘Ť
I found one way to solve this issue by manually re-output a new binary json file with following code, rb
stand for “read and binary”, wb
for “write and binary”.
First, go to shell:
python manage.py shell
Second, rewrite the test.json to a binary file:
with open('path/to/test.json', 'rb') as f:
data = f.read()
newdata = open('newfile.json', 'wb')
newdata.write(data)
newdata.close()
exit()
Then you can load the file:
python manage.py loaddata newfile.json
Above code works for me. Hope it can help you as well.
- Django Proxy Model Permissions Do Not Appear
- How to know what django version i use? is it 1.0, 1.1, or 1.2?
- Docker + Celery tells me not to run as root, but once I don't, I lack permissions to run
- Good tool for automatic setup and deployment of Django projects
2đź‘Ť
i encountered the same problem when loading data. it has a problem with encodings. install notepad ++. and change the encoding format to UTF-8
in the lower right corner you can see the current encoding. if it is not UTF- 8, you can simply change it to UTF-8 form the encoding menu tab.
this solution worked for me.
- Can I detect if my code is running on cPython or Jython?
- How do you raise a python exception and include additional data for Sentry?
- Celery – minimize memory consumption
- How can I get the Django admin's "View on site" link to work?
- Django, REST and Angular Routes
1đź‘Ť
If you are using newer versions of windows 10 you can use notepad to change the encoding from UTF-16 to UTF-8 simply by saving the file again and selecting the encoding option on the save dialog. See the example image below.
- Auto-creating related objects on model creation in Django
- Filter on datetime closest to the given datetime