3

I want build a blog with Python 2.7 and Django 1.7.8.

When I use Django,I keep getting an error: UnicodeDecodeError. The relevant code is:

#coding: utf-8
from django.db import models
class Entry(models.Model):
 title = models.CharField(max_length=200)
 body = models.TextField()
 publish = models.BooleanField(default=False)

And ./manage.py makemigrations get an error:

 Migrations for 'blog':
 0001_initial.py:
 - Create model Entry
Traceback (most recent call last):
 File "manage.py", line 10, in <module>
 execute_from_command_line(sys.argv)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_line
 utility.execute()
 File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/__init__.py", line 377, in execute
 self.fetch_command(subcommand).run_from_argv(self.argv)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/base.py", line 288, in run_from_argv
 self.execute(*args, **options.__dict__)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/base.py", line 338, in execute
 output = self.handle(*args, **options)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/commands/makemigrations.py", line 124, in handle
 self.write_migration_files(changes)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/core/management/commands/makemigrations.py", line 143, in write_migration_files
 migrations_directory = os.path.dirname(writer.path)
 File "/usr/local/lib/python2.7/dist-packages/Django-1.7.8-py2.7.egg/django/db/migrations/writer.py", line 222, in path
 return os.path.join(basedir, self.filename)
 File "/usr/lib/python2.7/posixpath.py", line 80, in join
 path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 10: ordinal not in range(128)

I don't see what's going wrong, any idea? I already add coding:utf-8 in top of code

M.javid
6,6324 gold badges44 silver badges58 bronze badges
asked Aug 17, 2015 at 16:29
2
  • 1
    Without a full stacktrace including files and line numbers involved, your error pasting is of no use. Commented Aug 17, 2015 at 16:33
  • It seems that makemigrations is trying to produce a migration name and that name is non-ascii. Do you have anything non-ascii in your data models, or in file names? Commented Aug 17, 2015 at 20:29

2 Answers 2

1

do you have data in the models already? if so, i am guessing you have some bad characters in there. do you have a unicode or str method defined on the models? if so, i suggest using them in a try statement of sorts like this:

def __str__():
 try:
 return "%s" % self.title
 except:
 return "%s" % self.pk

when you see only the PK, you will know that your 'title' field has bad data. extend this to include whichever fields you want to display, not just title.

answered Aug 17, 2015 at 17:06
Sign up to request clarification or add additional context in comments.

1 Comment

Nothing data in models.
1

it looks like it fails when joining the path?

maybe you have folder names that can't be converted to ascii?

also , consider editing the file that is having the error? maybe add a print statement just before the line that fails that shows what is trying to be joined?

edit the file mentioned below, add the print statement to see what is trying to be joined?

File "/usr/lib/python2.7/posixpath.py", line 80, in join
path += '/' + b
answered Aug 18, 2015 at 18:10

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.