How to create arrayType for WSDL in Python (using suds)?

假装没事ソ 提交于 2019-12-03 01:41:22
llemeur

I'm in the same case, with a RPC/encoded style WS and a method that contains a soap array. a print request (where request = client.factory.create('Request')) gives:

(Request){
  requestid = None
  option = 
    (ArrayOfOption){
     _arrayType = ""
     _offset = ""
     _id = ""
     _href = ""
     _arrayType = ""
  }
 }

The solution given by Jacques (1request.option.append(option1)1) does not work, as it ends with an error message ArrayOfOption instance has no attribute append.

The solution given by mcauth looks like this:

array = client.factory.create('ArrayOfOption')
array.item = [option1,  option2,  option3,  option4,  option5,  option6]
request.option=array

It works so so, as the resulting SOAP message shows no arrayType attribute:

<option xsi:type="ns3:ArrayOfOption">

The best solution I found is also the simplest:

request.option = [option1,  option2,  option3,  option4,  option5,  option6]

It ends with a good SOAP message:

<option xsi:type="ns0:ArrayOfOption" ns3:arrayType="ns0:Option[6]">

as expected by the server side WS.

I believe what you are looking for is:

itinerary0 = self.client.factory.create('itinerary')
itineraryArray = self.client.factory.create('itineraryArray')
print itineraryArray
itineraryArray.itinerary.append(itinerary0)

Just had to do this myself;) What helped me find it was printing to the console. That would have probably given you the following:

 (itineraryArray){
   itinerary[] = <empty>
 }

Cheers,Jacques

mcauth

For this type of structure I set an attribute called 'item' on the array object and then append the list member to it. Something like:

itineraryArray = self.client.factory.create('itineraryArray')
itineraryArray.item = [itinerary0]

Which parses and passes in fine, even for complex calls with multiple levels.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!