简体   繁体   中英

Django Unicode Decode Error when using startproject command Mac OS X Snow Leopard

I am brand new to Django and I am having a big problem right off the bat. I cannot use startproject to begin my web app.

When I use this command:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/bin/django-admin.py startproject cms

I get this error:

UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position 37: invalid start byte

and then it doesn't create the web app. I have not even done any programming and it seems like this is something that is wrong with the Django files, but I am really confused as how their own files would have a character not in the English language that would be making this error. I have been searching online and I have found people with Unicode Decode Errors, but not any during this specific step and I have not been able to find an answer so far. I am running Django on a Mac with Snow Leopard and am using the stable version of Django with Python 2.7. I have been trying to figure this out for a while now and I just keep hitting walls, I would really like to try Django. Thanks for any help!

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM