tags:

views:

78

answers:

3

I'm trying to use suds but have so far been unsuccessful at figuring this out. Hopefully it's something simple that i'm missing. Any help would be highly appreciated.

This is supposed to be the raw soap message that i need to achieve:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:api="http://api.service.apimember.soapservice.com/"&gt;
    <soapenv:Header/>
    <soapenv:Body>
        <api:insertOrUpdateMemberByObj>
        <token>t67GFCygjhkjyUy8y9hkjhlkjhuii</token>
             <member>
                 <dynContent>
                     <entry>
                         <key>FIRSTNAME</key>
                         <value>hhhhbbbbb</value>
                     </entry>
                 </dynContent>
                 <email>[email protected]</email>
             </member>
         </api:insertOrUpdateMemberByObj>
     </soapenv:Body>
</soapenv:Envelope>

So i use suds to create the member object:

member = client.factory.create('member')

produces:

(apiMember){
   attributes =
      (attributes){
         entry[] = <empty>
      }
 }

How exactly do i append an 'entry'?

I try this:

member.attributes.entry.append({'key':'FIRSTNAME','value':'test'})

and that produces this:

(apiMember){
   attributes =
      (attributes){
         entry[] =
            {
               value = "test"
               key = "FIRSTNAME"
            },
      }
 }

However, what i actually need is:

(apiMember){
   attributes =
      (attributes){
         entry[] =
            (entry) {
               value = "test"
               key = "FIRSTNAME"
            },
      }
 }

How do i achieve this?

A: 

Off the top of my head (all the suds stuff is at work at the moment)

member = client.factory.create('member')
entry = client.factory.create('attributes')
entry.key="FIRSTNAME"
entry.value="test"
member.attributes.entry.append(entry)

This does depend on the WSDL that defines your SOAP connection, but attributes should also be a structure defined in the WSDL.

Simon Callan
A: 

This is what happens when i try to create "entry":

>>> member = client.factory.create('member')
>>> entry = client.factory.create('attributes')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build\bdist.win32\egg\suds\client.py", line 231, in create
suds.TypeNotFound: Type not found: 'attributes'
>>>
Jerome
What heppens if you type "client.factory.create('member.attributes')"?Also, can you post the part of the WSDL that defines the "member" type?
Simon Callan
Thanks for your help on this Simon. client.factory.create('member.attributes.entry') solved it.
Jerome
A: 

Try this, a similar thing worked using my WSDL.

member.attributes.entry = {'key':'FIRSTNAME','value':'test'}

As simon said, it does depend on your WSDL.

chrissygormley