Python SOAP Client Nested Request
Question: I got a problem with a Python SOAP request. I tested two python SOAP client
libraries so far: SUDS and pysimplesoap. Both work well for the following
example:

    
    
    from suds.client import Client
    from pysimplesoap.client import SoapClient, SoapFault
    
    # suds example
    url = "http://www.webservicex.net/geoipservice.asmx?WSDL"
    client = Client(url, cache=None)
    
    print client.service.GetGeoIP((ip))
    
    
    # pysimplesoap example
    client = SoapClient(wsdl="http://www.webservicex.net/geoipservice.asmx?WSDL")
    
    # call the remote method
    response = client.GetGeoIP(("10.0.1.152"))
    
    print response
    

Both work fine and give me the expected response:

    
    
    {'GetGeoIPResult': {'ReturnCodeDetails': 'Success', 'IP': '10.0.1.152', 'ReturnCode': 1, 'CountryName': 'Reserved', 'CountryCode': 'ZZZ'}}
    

With a UI SOAP testing programm the request looks like this:

    
    
    -<soap:Envelope>
        -<soap:Body>
            -<GetGeoIP>
                <IPAddress>("10.0.1.152")</IPAddress>
            </GetGeoIP>
        </soap:Body>
    </soap:Envelope>
    

Now the problem is, I need to contact another WS via SOAP, but that doesn't
work. With the UI SOAP program it works (keys and token can be empty) and
looks like:

    
    
    -<soap:Envelope>
        -<soap:Body>
            -<getNews>
                -<shrequest>
                    <data>{'account_number':202VA7, 'track_nr':1757345939}</data>
                    <function>getnewsdata</function>
                    <keys/>
                    <token/>
                </shrequest>
            </getNews>
         </soap:Body>
     </soap:Envelope>
    

But my code doesn't work:

    
    
    url = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    client = Client(url, cache=None)
    
    data = "{'account_number':202VA7, 'track_nr':1757345939}"
    function = "getnewsdata"
    keys = ""
    token = ""
    shrequest = [data,function,keys,token]
    
    response = client.service.getNews(shrequest)
    
    print response
    

I get:

    
    
    ValueError('Invalid Args Structure. Errors: %s' % errors)
    ValueError: Invalid Args Structure. Errors:
    

How do I have to nest my request right?


Answer: I finally solved it. The SUDS library offers sth. nice:

    
    
    url = "xxxxxxxxxxxxxxxxxxxxxxxxx?wsdl"
    client = Client(url, cache=None)
    
    # Creating 'shrequest' obj. before the request
    shrequest = client.factory.create('shrequest')
    shrequest.data = "{'account_number':202VA7, 'track_nr':1757345939}"
    shrequest.function = "getnewsdata"
    
    response = client.service.getShipment(shrequest)
    
    print response
    

