python - SUDS does not parse response as array (only the first entry thereof is returned) -
python - SUDS does not parse response as array (only the first entry thereof is returned) -
a request using the suds library soap web service should homecoming array of envelopetype instances (don't inquire me type naming) instead only first entry of array parsed , returned. wsdl:type of response defined as:
<wsdl:types> <xs:element name="shipmentssearchdfures"> <xs:annotation> <xs:documentation>comment describing root element</xs:documentation> </xs:annotation> <xs:complextype> <xs:sequence minoccurs="0" maxoccurs="unbounded"> <xs:element name="zenvelope" type="dfu:envelopetype"/> </xs:sequence> </xs:complextype> </xs:element> </wsdl:types> and sample raw xml response (as obtained client.last_received()) yields:
<?xml version="1.0" encoding="utf-8"?> <soap:envelope> <soap:body> <ns11:shipmentssearchdfures> <envelope version="2.2"> <fileinfos fileid="1" filetime="16:10:13.110+02:00" filedate="2014-06-18+02:00" /> <data> <!-- ... omitted brevity ... --> </data> </envelope> <envelope version="2.2"> <fileinfos fileid="2" filetime="16:12:13.117+02:00" filedate="2014-06-18+02:00"/> <data> <!-- ... --> </data> </envelope> </ns11:shipmentssearchdfures> </soap:body> </soap:envelope> i'm no means soap expert i'd expect calling
client.service.shipmentssearch(...) would homecoming array of envelopetype instances here only first entry, i.e. fileid="1", returned. is, instead of returning:
[envelope_1, envelope_2] i envelope_1. 1000000 help.
note #1: mere consumer of webservice.
note #2: php soap client homecoming array of both envelopetype instances. wrong suds? or wsdl?
the partial parsing can partly blamed on erroneous type definition as
<xs:sequence minoccurs="0" maxoccurs="unbounded"> <xs:element name="zenvelope" type="dfu:envelopetype"/> </xs:sequence> should read:
<xs:sequence> <xs:element name="zenvelope" type="dfu:envelopetype" minoccurs="0" maxoccurs="unbounded"/> </xs:sequence> according xml schema @ w3.org. using local re-create of wsdl , referenced files therein above changes solves problem.
if must know, when parsing raw xml response suds utilize xsd schema , ultimate reason bad parsing due surprisingly stiff handling of root nodes on lines 158–161 of binding.get_reply() method (in bindings/binding.py):
130 def get_reply(self, method, reply): 131 """ 132 process i{reply} specified i{method} sax parsing i{reply} 133 , unmarshalling python object(s). 134 @param method: name of invoked method. 135 @type method: str 136 @param reply: reply xml received after invoking specified method. 137 @type reply: str 138 @return: unmarshalled reply. returned value l{object} 139 i{list} depending on whether service returns single object or 140 collection. 141 @rtype: tuple ( l{element}, l{object} ) 142 """ 143 reply = self.replyfilter(reply) 144 sax = parser() 145 replyroot = sax.parse(string=reply) 146 plugins = plugincontainer(self.options().plugins) 147 plugins.message.parsed(reply=replyroot) 148 soapenv = replyroot.getchild('envelope') 149 soapenv.promoteprefixes() 150 soapbody = soapenv.getchild('body') 151 self.detect_fault(soapbody) 152 soapbody = self.multiref.process(soapbody) 153 nodes = self.replycontent(method, soapbody) 154 rtypes = self.returned_types(method) 155 if len(rtypes) > 1: 156 result = self.replycomposite(rtypes, nodes) 157 homecoming (replyroot, result) 158 if len(rtypes) == 1: 159 if rtypes[0].unbounded(): 160 result = self.replylist(rtypes[0], nodes) 161 homecoming (replyroot, result) 162 if len(nodes): 163 unmarshaller = self.unmarshaller() 164 resolved = rtypes[0].resolve(nobuiltin=true) 165 result = unmarshaller.process(nodes[0], resolved) 166 homecoming (replyroot, result) 167 homecoming (replyroot, none) where author solely relies on type definition regardless of size of nodes list. specifically, think test on line 159 should rather read:
158 if len(rtypes) == 1: 159 if rtypes[0].unbounded() or len(nodes)>1: 160 result = self.replylist(rtypes[0], nodes) 161 homecoming (replyroot, result) perhaps warning of mismatch between xsd , actual response. hth.
python python-2.7 soap soap-client suds
Comments
Post a Comment