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

Visto 35 veces
Saltar al primer mensaje no leído

Hossein Rashnoo

no leída,
29 dic 2014, 2:33:4929/12/14
a django...@googlegroups.com
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.

Hossein Rashnoo

no leída,
29 dic 2014, 2:52:2429/12/14
a django...@googlegroups.com

I Solved that with this code:

fname = fname.encode('ascii', 'xmlcharrefreplace')
xml = r"""my XML code with unicode {0} """.format(fname)
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos