Sunday, December 28, 2014

uni-code error in python : 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

Hi
I use django and in my view i need to send a request as XML with some uni-code character that received from html page with post method. I tried these (Note that i save that input in fname variable)  : 

    xml = r"""my XML code with uni-code {0} """.format(fname)

And

    fname = u"%s".encode('utf8') % (fname)
    xml = r"""my XML code with uni-code {0} """.format(fname)

And

    fname = fname.encode('ascii', 'ignore').decode('ascii')
    xml = r"""my XML code with uni-code {0} """.format(fname)

And every time i got this error:

    'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

Please help me.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ae41cdad-dc75-49be-8d93-ef308e2fe0f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment