kartagis / pysimplesoap

Automatically exported from code.google.com/p/pysimplesoap
0 stars 0 forks source link

unicode text doesn't work properly #15

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

When using pysimplesoap with the new wsfev1 afip webservice, I got the 
following error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal 
not in range(128)

(This was for listing bill types, with the 'Nota de Débito' value).  In order 
to fix it, I changed the way that the unicode function was being applied to the 
values.

I'm not sure if it's the best way, but this one at least works.

diff -r 9dc392f4a0ec simplexml.py
--- a/simplexml.py      Wed Oct 20 03:59:29 2010 -0300
+++ b/simplexml.py      Fri Oct 29 11:30:26 2010 -0300
@@ -355,7 +355,10 @@
                     try:
                         # get special desserialization function (if any)
                         fn = TYPE_UNMARSHAL_FN.get(fn,fn) 
-                        value = fn(unicode(node))
+                        if fn == str:
+                            value = fn(node).decode("utf-8")
+                        else:
+                            value = fn(node)
                     except (ValueError, TypeError), e:
                         raise ValueError("Tag: %s: %s" % (name, unicode(e)))
                 else:

Original issue reported on code.google.com by margamanterola on 29 Oct 2010 at 2:34

Attachments:

GoogleCodeExporter commented 8 years ago
Did you see issue #10?

I think str should be removed at all, as almost all webservice communication is 
done in utf-8.

Can you provide a test case?

Original comment by reingart@gmail.com on 23 Nov 2010 at 11:33

GoogleCodeExporter commented 8 years ago
Change commited (thanks margamanterola)
Needs testing

Original comment by reingart@gmail.com on 3 May 2011 at 12:17

GoogleCodeExporter commented 8 years ago
node are SimpleXmlElement objects, they need to be converted to unicode/string 
prior applying the conversion function.

Fixed in Revision 6652e405370d

Original comment by reingart@gmail.com on 3 May 2011 at 9:13