views:

203

answers:

1

I need to send a SOAP message (with Python SUDS) with strings encoded in 'iso-8859-2'. Does anybody know how to do it?

SUDS raises the following exception when I invoke a method on a client with parameters encoded in 'iso-8859-2':

File "/home/bartek/myenv/lib/python2.5/site-packages/suds/sax/text.py", line 43, in __new__
   result = super(Text, cls).__new__(cls, *args, **kwargs)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 10: ordinal not in range(128)
A: 
Text = Text.decode('iso-8859-2')

might be all you need, if Text starts out as an 8-bit string that was encoded with iso-8859-2. If it needs to be sent as a UTF-8 string or something, however, then you'd probably want to use

Text = Text.decode('utf-8')

If neither of those, then just play around with the decode() and encode() methods and the error handling methods used with them: http://docs.python.org/release/2.5/lib/string-methods.html

(Took out most of the stuff in my answer that wasn't really necessary, considering what the question states.)

JAB
Shouldn't it be the other way around? `Text.decode('iso-8859-2').encode('utf-8')`?
Tim Pietzcker
@Tim: Oh, possibly.
JAB
Nope, it doesn't work with SUDS.suds/sax/text.py takes the string given as a SOAP argument and calls unicode() on it. Unicode() then raises an exception. Try:unicode('ą'.decode('iso-8859-2').encode('utf-8'))I think it's more probable that there is some SUDS setting that can change UTF to ISO-8859-2.
bartekb
@bartekb: Ah well. I haven't used SUDS before, so I can't really help you there.
JAB