Suds and Complex Sequences

dieter dieter at handshake.de
Wed Sep 18 02:16:07 EDT 2013


Greg Lindstrom <gslindstrom at gmail.com> writes:

> I am trying to use Suds, the very fine library allowing me to use SOAP, to
> query a service over the net.  Part of the data structure defined be the
> WSDL calls for a sequence of SubscriberDataTypes (this application is used
> to test an insurance companys' rating service).
>
> (SubscriberDataType){
>    SubscriberID = None
>    SubscriberBirthDate = None
>    Zip = None
>    <snip>
>    DependentData[] = <empty>
>  }
>
> Which goes into
>
> (MedicalRatingRequest){
>    MessageHeader =
>       (MessageHeaderType){
>          MessageName = None
>          MessageID = None
>          <snip>
>       }
>    RequestHeader =
>       (RequestHeaderType){
>          RequestType =
>             (RequestTypeEnum){
>                value = None
>             }
>          <snip>
>       }
>    <snip>
>    SubscriberData[] = <empty>
>  }
>
> Note that the Subscriber Data is a sequence of SubscriberDataType.  I have
> not been able to find any documentation showing me how to do this.  Does
> anyone out there know how I can generate the request?

A suds client as two major components: the "service" itself, and
the so called "factory". You can use the "factory" to create Python
objects corresponding to a type defined in the WSDL.

To pass a list of complex type, you use the factory to
create Python objects for the list components, set these objects'
attributes in any way appropriate and build of Python list of
them and assign the list or "append" them directly to the list
values attribute.

In your case, it may look somehow like:

   sd = client.factory("SubscriberDataType") # create a SubscriberDataType Python object
   sd.SubscriberID = ... # assign values for its attributes
   ....
   mrr = client.factory("MedicalRatingRequest")
   mrr.SubscriberData.append(sd) # append our "sd"
or
   mrr.SubscriberData = [sd] # assign a list




More information about the Python-list mailing list