无法创建未在suds中列出的数组类型实例
我正在制作一个客户端,用来访问一个WSDL(网络服务描述语言)并打印出响应内容。之后我还想把这个响应显示在网页上。不过现在我在最初的代码部分遇到了麻烦。我觉得suds(一个Python库)生成的客户端方法签名和给定的WSDL不匹配。以下是我的代码和我遇到的错误:
print client
Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913
Service ( IWS_GeocodeService_GB ) tns="http://www.g1.com/"
Prefixes (1)
ns0 = "http://www.g1.com/services/IWS_GeocodeService_GB"
Ports (1):
(IWS_GeocodeService_GBPort)
Methods (1):
IWS_GeocodeService_GB(ns0:context context, ns0:options options, ns0:rows rows, )
Types (7):
ns0:IWS_GeocodeService_GBRequest
ns0:IWS_GeocodeService_GBResponse
ns0:context
ns0:options
ns0:requestRow
ns0:responseRow
ns0:user_field
>>> print context1
(context){
account.id = "spectrumd3v"
account.password = "spectrumd3v"
}
>>> rows = client.factory.create('ns0:rows')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/client.py", line 234, in create
raise TypeNotFound(name)
suds.TypeNotFound: Type not found: 'ns0:rows'
我不明白为什么它会首先找到nso:rows。因为在WSDL定义中,这个类型是responseRow对象,但它却期待一个row对象……所以我无法发送消息请求!我需要在requestRow对象中发送详细信息。求助!我对这些还很陌生……
补充:我尝试发送一个Request对象,而不是rows……结果也不行,我得到了以下错误
>>> resp = client.service.IWS_GeocodeService_GB(context,options,Request)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/client.py", line 602, in invoke
result = self.send(soapenv)
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/client.py", line 649, in send
result = self.failed(binding, e)
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/client.py", line 702, in failed
r, p = binding.get_fault(reply)
File "/usr/local/lib/python2.7/dist-packages/suds-0.4-py2.7.egg/suds/bindings/binding.py", line 265, in get_fault
raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'Unmarshalling Error: unexpected element (uri:"http://www.g1.com/services/IWS_GeocodeService_GB", local:"context"). Expected elements are <{http://www.g1.com/services/IWS_GeocodeService_GB}row> '
我也附上了相关的XML内容
<wsdl:definitions name="IWS_GeocodeService_GB" targetNamespace="http://www.g1.com/">
<wsdl:types>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://www.g1.com/services/IWS_GeocodeService_GB">
<xs:element name="requestRow" type="tns:requestRow"/>
<xs:element name="responseRow" type="tns:responseRow"/>
<xs:complexType name="IWS_GeocodeService_GBRequest">
<xs:sequence>
<xs:element form="qualified" name="context" type="tns:context"/>
<xs:element form="qualified" minOccurs="0" name="options" type="tns:options"/>
<xs:element form="qualified" name="rows">
<xs:complexType>
<xs:sequence>
<xs:element form="qualified" maxOccurs="unbounded" name="row" type="tns:requestRow"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="context">
<xs:sequence>
<xs:element form="qualified" name="account.id" type="xs:string"/>
<xs:element form="qualified" minOccurs="0" name="account.password" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="options">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="requestRow">
<xs:all>
<xs:element form="qualified" minOccurs="0" name="AddressLine1" type="xs:string"/>
<xs:element form="qualified" minOccurs="0" name="AddressLine2" type="xs:string"/>
<xs:element form="qualified" minOccurs="0" name="City" type="xs:string"/>
<xs:element form="qualified" minOccurs="0" name="PostalCode" type="xs:string"/>
<xs:element form="qualified" minOccurs="0" name="Country" type="xs:string"/>
<xs:element form="qualified" minOccurs="0" name="user_fields"><xs:complexType>
1 个回答
0
问题解决了!这里的行其实就是一个Python列表。我只需要在里面添加一个类型为requestRow的行对象,这样就解决了我的问题!