A Problem about UnicodeEncodeError

1,206 views
Skip to first unread message

nku...@gmail.com

unread,
Apr 22, 2016, 9:09:23 AM4/22/16
to Django users
Hello,
I'm a beginner of Python.
Recently,I want to learn something about django.But I meet a problem:
    I created a django project following the tutorial successfully , but when I ran the command "python manage.py runserver",

    the cmd show the error information:
        UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character

I have search for a long time but didn't get the solution.
Could anyone please tell me how to fix it?
Thanks.

P.S.The veision of my python is 3.5.1,and the version of django is 1.9.5.My OS is windows8.1

Steven Crockett

unread,
Apr 22, 2016, 10:41:29 AM4/22/16
to Django users
Hi. Could you post more of the exception traceback?

Here is a workaround others have found for a problem similar to yours:

It seems to be something to do with your PATH setting within Windows possibly containing some non-standard character.

nku...@gmail.com

unread,
Apr 23, 2016, 11:48:50 PM4/23/16
to Django users
Yeah,this problem is same as what I met.
However the solution the author provided didn't work on my machine.
My friend started the project successfully with python2.x,so I decided to change the version of python.
Thank you very much for your help!

在 2016年4月22日星期五 UTC+8下午10:41:29,Steven Crockett写道:

Mike Dewhirst

unread,
Apr 24, 2016, 12:56:26 AM4/24/16
to django...@googlegroups.com
On 24/04/2016 1:48 PM, nku...@gmail.com wrote:
> Yeah,this problem is same as what I met.
> However the solution the author provided didn't work on my machine.
> My friend started the project successfully with python2.x,so I decided
> to change the version of python.
> Thank you very much for your help!
>
> 在 2016å¹´4月22日星期五 UTC+8ä¸‹å ˆ10:41:29,Steven Crockettå†™é “ï¼š
>
> Hi. Could you post more of the exception traceback?
>
> Here is a workaround others have found for a problem similar to yours:
> https://code.djangoproject.com/ticket/23704
> <https://code.djangoproject.com/ticket/23704>

If you look at the path displayed in that ticket and pointed to by the
little blue arrow, you can see the Django project ("myfirstapp") is
created in the desktop folder.

I believe that is the problem. The desktop is a magic place in Windows
and I have no doubt that Microsoft uses "special" characters in the path
so it recognises the desktop to perform its magic.

It is probably mis-recognised by Python as a 'mbcs' encoding and causes
the error.

I have been using Python 2 and 3 on Windows for years without problems -
which knowing Microsoft I consider to be something of a miracle!

Move your project off the desktop and you won't need any workarounds.

Mike




>
> It seems to be something to do with your PATH setting within Windows
> possibly containing some non-standard character.
>
>
> On Friday, April 22, 2016 at 9:09:23 AM UTC-4, nku...@gmail.com wrote:
>
> Hello,
> I'm a beginner of Python.
> Recently,I want to learn something about django.But I meet a
> problem:
> Â Â I created a django project following the tutorial
> successfully , but when I ran the command "python manage.py
> runserver",
>
> Â Â the cmd show the error information:
> Â Â Â Â Â Â Â UnicodeEncodeError: 'mbcs' codec can't encode
> characters in position 0--1: invalid character
>
> I have search for a long time but didn't get the solution.
> Could anyone please tell me how to fix it?
> Thanks.
>
> P.S.The veision of my python is 3.5.1,and the version of django
> is 1.9.5.My <http://1.9.5.My> OS is windows8.1
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8555253a-973a-40af-9ea3-5ecd2c62d4ed%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8555253a-973a-40af-9ea3-5ecd2c62d4ed%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

nku...@gmail.com

unread,
Apr 25, 2016, 8:29:45 AM4/25/16
to Django users
Thank you for your help.
But my project is not in the desktop folder.
I'll show you the traceback information:



在 2016年4月24日星期日 UTC+8下午12:56:26,Mike Dewhirst写道:

Mike Dewhirst

unread,
Apr 25, 2016, 7:14:12 PM4/25/16
to django...@googlegroups.com
On 25/04/2016 10:29 PM, nku...@gmail.com wrote:
> Thank you for your help.
> But my project is not in the desktop folder.
> I'll show you the traceback information:

Well I don't think I can help. I can say that my development setup has
given me no trouble at all. What works for me is ...

C:\Users\mike\env\<project_name>

... for all the projects I work on

I use virtualenv to isolate the various development environments. Also I
make sure there are no spaces in filenames or directory names and I only
use ascii characters in filenames and directory names.

mbcs characters in a path feels like a Windows error to me.

But I can't suggest anything

All the best

Mike


>
> <https://lh3.googleusercontent.com/-MZAvxNMe7cA/Vx4NO9k8EpI/AAAAAAAAAAM/dGnK97FqJeEJYl6cPQTEvj_hUQDb64rsQCLcB/s1600/pic1.JPG>
>
>
>
> 在 2016å¹´4月24日星期日 UTC+8ä¸‹å ˆ12:56:26,Mike Dewhirstå†™é “ï¼š
>
> On 24/04/2016 1:48 PM, nku...@gmail.com <javascript:> wrote:
> > Yeah,this problem is same as what I met.
> > However the solution the author provided didn't work on my machine.
> > My friend started the project successfully with python2.x,so I
> decided
> > to change the version of python.
> > Thank you very much for your help!
> >
> > 在 2016å¹´4月22日星期äºâ€
> UTC+8ä¸‹å ˆ10:41:29,Steven Crockettå†™é “ï¼š
> >
> > Â Â Hi. Could you post more of the exception traceback?
> >
> > Â Â Here is a workaround others have found for a problem
> similar to yours:
> > Â Â https://code.djangoproject.com/ticket/23704
> <https://code.djangoproject.com/ticket/23704>
> > Â Â <https://code.djangoproject.com/ticket/23704
> <https://code.djangoproject.com/ticket/23704>>
>
> If you look at the path displayed in that ticket and pointed to by the
> little blue arrow, you can see the Django project ("myfirstapp") is
> created in the desktop folder.
>
> I believe that is the problem. The desktop is a magic place in Windows
> and I have no doubt that Microsoft uses "special" characters in the
> path
> so it recognises the desktop to perform its magic.
>
> It is probably mis-recognised by Python as a 'mbcs' encoding and causes
> the error.
>
> I have been using Python 2 and 3 on Windows for years without
> problems -
> which knowing Microsoft I consider to be something of a miracle!
>
> Move your project off the desktop and you won't need any workarounds.
>
> Mike
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8a4c6412-78ff-453c-9bf7-8fda2f5ab127%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8a4c6412-78ff-453c-9bf7-8fda2f5ab127%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages