[Django]-How to solve UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

3👍

Turns out it was my .gitignore file that was encoded in UTF-16 that was the problem. This seemed to stop Black from working in the whole directory. When I moved all of my files to another directory, I only moved the visible files (so not .gitignore), hence the unusual behaviour. Changing the .gitignore to UTF-8 solved the problem.

👤Hambot

-3👍

I don’t even know what django is, but I had the same problem in a non-django program.
In that code fragment was the problem that now is fixed:

open(document.txt, mode= "r", encoding="utf8")

As you can see, the encoding it’s utf8, without the "-". I used that code to open documents and read it. I hope it’ll be useful!

Leave a comment