Python & suds - how can I get information about the type of a method parameter?
Asked Answered
A

0

9

I am calling methods in a SOAP API from my Python code using suds. I am trying to programmatically determine what information to send as parameters to the methods in the API. One of the WSDLs I'm looking at is here.

There is a method defined in that WSDL with the following signature:

GetActiveDirectoryObjects(FilterOptions filterOptions)

I can use suds to create a client for this WSDL and then I can use client.factory.create() method as follows:

from suds.client import Client
client = Client('https://controlpanel.msoutlookonline.net/WebServices/ActiveDirectory/ActiveDirectoryService.asmx?WSDL')
client.factory.create('FilterOptions')

output is:

(FilterOptions){
   AttributesToRead =
      (ArrayOfString){
         string[] = <empty>
      }
   SortBy = None
   SortDirection =
      (SortDirection){
         value = None
      }
   ResultSize = None
   Filter =
      (AndOperation){
         ExtensionData = None
      }
   SearchBase = None
 }

What I can't figure out is how I can determine, using suds, whether 'SortBy' wants to be assigned a string or an int or a boolean, or what. I know 'AttributesToRead' wants to be assigned an 'ArrayOfString'. I know 'SortDirection' wants to be assigned an object of type 'SortDirection'. But what about SearchBase? ResultSize? How can my program determine whether the auto-generated form should contain a field that will validate for an int or for a boolean or for a string?

Looking at the WSDL XML I see the following:

<s:complexType name="FilterOptions">
    <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="AttributesToRead" type="tns:ArrayOfString"/>
        <s:element minOccurs="0" maxOccurs="1" name="SortBy" type="s:string"/>
        <s:element minOccurs="1" maxOccurs="1" name="SortDirection" type="tns:SortDirection"/>
        <s:element minOccurs="0" maxOccurs="1" name="ResultSize" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="Filter" type="tns:AndOperation"/>
        <s:element minOccurs="0" maxOccurs="1" name="SearchBase" type="s:string"/>
    </s:sequence>
</s:complexType>

So I know from reading the XML manually that 'SortBy' wants to be assigned a string -- but how can I figure this out programmatically using suds? I don't want to spend days writing code that parses the XML to figure this out when the people who wrote suds already followed the SOAP specs closely -- but what is the secret to getting suds to tell me that 'SortBy' should be of type 'string'?

Ann answered 20/3, 2013 at 1:20 Comment(1)
I think #9501126 has the answer. priv_el.name priv_el.typeArgo

© 2022 - 2024 — McMap. All rights reserved.