Sunday, December 28, 2014

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

I Solved that with this code:

fname = fname.encode('ascii', 'xmlcharrefreplace')  xml = r"""my XML code with unicode {0} """.format(fname)

On Monday, December 29, 2014 11:03:49 AM UTC+3:30, Hossein Rashnoo wrote:
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/bc6c1f66-6c1e-49b8-baba-7431cb2e2d4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment