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

Environment:

  • Python v2.6.2
  • suds v0.3.7

The WSDL (server) I am working with has the following subsections of the schema (I tried to write it using plain text) -


[subsection # 1]

searchRequest: (searchRequest){ userIdentification = (userIdentification){ username = "" password = "" } itineraryArr = (itineraryArray){ _arrayType = "" _offset = "" _id = "" _href = "" _arrayType = "" } ... ... 

[subsection # 2]

 itinerary: (itinerary){ departurePoint = (locationPoint){ locationId = None radius = None } arrivalPoint = (locationPoint){ locationId = None radius = None } ... ... 

No problem with "userIdentification" (which is a "simple" type)

But "itineraryArr" is an array of a "route", and I don't know how to use python to create an XML array.

I tried several combinations, for example

 itinerary0 = self.client.factory.create('itinerary') itineraryArray = self.client.factory.create('itineraryArray') itineraryArray = [itinerary0] searchRequest.itineraryArr = itineraryArray 

But all my tests led to the same server error -

  Server raised fault: 'Cannot use object of type itinerary as array' (Fault){ faultcode = "SOAP-ENV:Server" faultstring = "Cannot use object of type itinerary as array" } 
+6
python arrays wsdl xml suds
source share
3 answers

I am in the same case, with WSX / WS encoded style and a method containing a soap array. a print request = client.factory.create('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, because it ends with the error message ArrayOfOption instance has no attribute append .

The solution given by mcauth is as follows:

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

It works like this because the arrayType attribute is not displayed as a result of the SOAP message:

 <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 on the server side of WS.

+6
source share

I believe what you are looking for:

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

I just had to do it myself;) What helped me find that it was a print on the console. This would probably give you the following:

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

Cheers Jacques

+4
source share

For this type of structure, I set an attribute called "item" in the array object, and then add a list item to it. Something like:

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

which parses and transmits in order, even for complex calls with multiple levels.

+2
source share

All Articles