[Answer]-Django Unicode Decode Error when using startproject command Mac OS X Snow Leopard

1👍

I know this question is too old, but this problem gave me a big headache and I will share my solution so others can benefit.

I had exactly the same problem. In my case, the error was caused because when I unzippep the tar.gz file for the django installation every file in the archive had some sort of hidden security copy created by MacOS. So, the templates folder for django had a lot of hidden files with weird characters, which resulted on the error message “UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xb0 in position 37: invalid start byte” when the django-admin script tried to copy the templates to the destination folder. What I had to do was just find every file whose name started with “.” and delete them from the django installation folder.

I found out about this by doing a very easy debugging of django, and even if the cause of your problem is different this debugging technique may help you find out what is happening.

Reading the traceback when the error occurs I found out that the error happened on the function call content.decode(‘utf-8’), which in django 1.8.1 was made on the django\core\management\templates.py file, line 150. I opened the templates.py file, located the line and noticed that “content” is the content of the template file that is currently being read, which is stored in the variable “old_path”. Then edited the templates.py to print the value of the “old_path” variable before the call to content.decode(‘utf-8’) and, when I ran again the django-admin script, the name of the faulty file appeared on the command prompt. If you repeat this procedure you can check if the file contains weird characters and if maybe the file wasn’t supposed to be on the templates folder (as was my case).

Leave a comment