1

I am new on using pysimplesoap. I am succeed using pysimplesoap to generate a soap request to a SOAP server, and the soap server is responded correctly, however, I do not know how to extract the information returned.

This is my code on pysimplesoap for the request

> from pysimplesoap.client import SoapClient
> client = SoapClient(location="http://192.168.206.111:8998/axis2/services/SecurityService", action="", namespace="http://www.labtest.com/Security", ns="ns3")
> response = client.call("login", ("ns3:loginName", "administrator"), ("ns3:password", "admin"))

The SOAP response is in below format.

   <soapenv:Envelope
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
            <n:loginResponse
                xmlns:n="http://www.labtest.com/Security"
                xmlns:n0="http://www.labtest.com/Types">
                <n:errorCode>
                    <n0:hasError>
                        false
                        </n0:hasError>
                    <n0:status>
                        STATUS_SUCCESS
                        </n0:status>
                    </n:errorCode>
                <n:authorizationToken>
                    <n0:token>
                        6430303938366138316265646532313138623866353235343030346130653330
                        </n0:token>
                    <n0:securityPrivileges>
                        <n0:values>
                            <n0:securityAttribute>
                                SUPER_USER_ACCESS
                                </n0:securityAttribute>
                            <n0:accessRights>
                                <n0:values>
                                    FULL_CONTROL
                                    </n0:values>
                                </n0:accessRights>
                            </n0:values>
                        </n0:securityPrivileges>
                    </n:authorizationToken>
                </n:loginResponse>
            </soapenv:Body>
        </soapenv:Envelope>

I tried to use the print response or print (response), but nothing show up.

user1087418
  • 47
  • 1
  • 6

1 Answers1

2

The response object is a pysimplesoap.client.SimpleXMLElement.

Behind the hood, a print(response) will call its __str__() method, the choice have been made, for pysimplesoap that `__str__() returns the text content of the node (if any), if your node contains no text content, like :

<MySoapResponse>
    <child tag attr="value />
</MySoapResponse>

… then, __str__() will return nothing, and so do printing.

Alternatively, you may want to

  • navigate the XML tree of your answer by using SimpleXMLElement methods :
    • children() to grab childrens list
    • tag['attr'] (dict notation) to access attributes of an XML tag
    • tag.get_name() to get a tag name ;
  • inspect the full answer as a string (including Soap headers) as string calling repr(response), but it's more for debugging purposes.

See also the basic client documentation online.

Jocelyn delalande
  • 5,123
  • 3
  • 30
  • 34