如何在 Python SOAPpy 中设置 UTF-8
How to setup UTF-8 in Python SOAPpy
我尝试使用 SOAPpy 连接到网络服务。服务中的每个方法都使用用户名和密码进行身份验证。
密码有一个特殊的德语字符 ("ä")。
当我执行以下脚本时:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from SOAPpy import WSDL
server = WSDL.Proxy('http://www.example.com/xxx.asmx?WSDL')
server.HelloWorld("xxx","xxxäxxx")
我在终端中得到这个输出。
Traceback (most recent call last):
File "./test.py", line 6, in <module>
server.HelloWorld("xxx","xxxäxxx")
File "/usr/lib/pymodules/python2.7/SOAPpy/Client.py", line 470, in __call__
return self.__r_call(*args, **kw)
File "/usr/lib/pymodules/python2.7/SOAPpy/Client.py", line 492, in __r_call
self.__hd, self.__ma)
File "/usr/lib/pymodules/python2.7/SOAPpy/Client.py", line 354, in __call
config = self.config, noroot = self.noroot)
File "/usr/lib/pymodules/python2.7/SOAPpy/SOAPBuilder.py", line 636, in buildSOAP
return t.build()
File "/usr/lib/pymodules/python2.7/SOAPpy/SOAPBuilder.py", line 147, in build
self.dump(i, typed = typed, ns_map = ns_map)
File "/usr/lib/pymodules/python2.7/SOAPpy/SOAPBuilder.py", line 303, in dump
meth(obj, tag, typed, ns_map)
File "/usr/lib/pymodules/python2.7/SOAPpy/SOAPBuilder.py", line 376, in dump_string
typed, ns_map, self.genroot(ns_map), id))
File "/usr/lib/pymodules/python2.7/SOAPpy/SOAPBuilder.py", line 339, in dumper
"id": id, "attrs": a}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)
我如何 setup/init SOAPpy 使用 UTF-8?
您必须使用 unicode 字符串:
server.HelloWorld("xxx", u"xxxäxxx")
我尝试使用 SOAPpy 连接到网络服务。服务中的每个方法都使用用户名和密码进行身份验证。 密码有一个特殊的德语字符 ("ä")。
当我执行以下脚本时:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from SOAPpy import WSDL
server = WSDL.Proxy('http://www.example.com/xxx.asmx?WSDL')
server.HelloWorld("xxx","xxxäxxx")
我在终端中得到这个输出。
Traceback (most recent call last):
File "./test.py", line 6, in <module>
server.HelloWorld("xxx","xxxäxxx")
File "/usr/lib/pymodules/python2.7/SOAPpy/Client.py", line 470, in __call__
return self.__r_call(*args, **kw)
File "/usr/lib/pymodules/python2.7/SOAPpy/Client.py", line 492, in __r_call
self.__hd, self.__ma)
File "/usr/lib/pymodules/python2.7/SOAPpy/Client.py", line 354, in __call
config = self.config, noroot = self.noroot)
File "/usr/lib/pymodules/python2.7/SOAPpy/SOAPBuilder.py", line 636, in buildSOAP
return t.build()
File "/usr/lib/pymodules/python2.7/SOAPpy/SOAPBuilder.py", line 147, in build
self.dump(i, typed = typed, ns_map = ns_map)
File "/usr/lib/pymodules/python2.7/SOAPpy/SOAPBuilder.py", line 303, in dump
meth(obj, tag, typed, ns_map)
File "/usr/lib/pymodules/python2.7/SOAPpy/SOAPBuilder.py", line 376, in dump_string
typed, ns_map, self.genroot(ns_map), id))
File "/usr/lib/pymodules/python2.7/SOAPpy/SOAPBuilder.py", line 339, in dumper
"id": id, "attrs": a}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)
我如何 setup/init SOAPpy 使用 UTF-8?
您必须使用 unicode 字符串:
server.HelloWorld("xxx", u"xxxäxxx")