Python SUDS - 发送非 UTF-8 编码的消息时出现问题
我需要发送一条 SOAP 消息(使用 Python SUDS),其中包含以“iso-8859-2”编码的字符串。 有人知道该怎么做吗?
当我在客户端上调用参数以“iso-8859-2”编码的方法时,SUDS 引发以下异常:
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 Text 最初是使用 iso-8859-2 编码的 8 位字符串,那么这可能就是您所需要的。但是,如果需要将其作为 UTF-8 字符串或其他内容发送,那么您可能会想要使用
如果这两者都不是,那么只需使用
decode()
和encode()
方法以及与它们一起使用的错误处理方法: http://docs.python.org/release/2.5/lib/string-methods.html(考虑到问题的内容,删除了我的答案中并非真正必要的大部分内容。)
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
If neither of those, then just play around with the
decode()
andencode()
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.)