如何在Python SOAPpy中设置UTF-8

用户名

我尝试使用SOAPpy连接到Web服务。服务中的每个方法都使用用户名和密码进行身份验证。Passwort有一种特殊的德国字符(“ä”)。

当我执行以下脚本时:

#!/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)

如何设置/初始化SOAPpy以与UTF-8一起使用?

丹尼尔

您必须使用unicode字符串:

server.HelloWorld("xxx", u"xxxäxxx")

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TOP 榜单

热门标签

归档