shantanuo
shantanuo

Reputation: 32296

python response does not match with soapUI

When I access the web service using soapUI I get the correctly formatted text. But when I use the python code, I get a dictionary with all rows in a single allBusType key.

from pysimplesoap.client import SoapClient
url = 'http://180.92.171.93:8080/UPSRTCServices/UPSRTCService?wsdl'
namespace = 'http://service.upsrtc.trimax.com/'
client = SoapClient(wsdl=url, namespace=namespace, trace=True)
print client.GetBusTypes()

The above code returns the following:

{'return': {'allBusType': [{'busName': u'AC SLEEPER'}, {'busType': u'ACS'}, {'ischildconcession': u'N'}, {'isseatlayout': u'N'}, {'isseatnumber': u'N'}, {'busName': u'AC-JANRATH'}, {'busType': u'JNR'}, {'ischildconcession': u'N'}, {'isseatlayout': u'Y'}, {'isseatnumber': u'Y'},....

As per the following screen, soapUI is returning all the bus stops as separate tag. (And not all stops in a single tag as above)

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns3:GetBusTypesResponse xmlns:ns2="com.trimax.upsrtc.xml.jaxb.model" xmlns:ns3="http://service.upsrtc.trimax.com/">
         <return>
            <allBusType>
               <busName>AC SLEEPER</busName>
               <busType>ACS</busType>
               <ischildconcession>N</ischildconcession>
               <isseatlayout>N</isseatlayout>
               <isseatnumber>N</isseatnumber>
            </allBusType>
            <allBusType>
               <busName>AC-JANRATH</busName>
               <busType>JNR</busType>
               <ischildconcession>N</ischildconcession>
               <isseatlayout>Y</isseatlayout>
               <isseatnumber>Y</isseatnumber>
            </allBusType>

I will like to know if this is python issue or the server issue.

For each entry there is opening and closing tag called "allBusType" in the soapUI response that is missing in python response. Python output is returning a single row for all entries.

Upvotes: 1

Views: 2486

Answers (1)

Noelkd
Noelkd

Reputation: 7896

SoapClient returns a SimpleXmlElement as stated in the first line of the SoapClient docs:

A simple, minimal and functional HTTP SOAP webservice consumer, using httplib2 for the connection ad SimpleXmlElement for the XML request/response manipulation.

Therefore to view it as xml you need to call the as_xml method on the returned SimpleXmlElement:

as_xml(pretty=False): Return the XML representation of the document

The following should work:

from pysimplesoap.client import SoapClient
url = 'http://180.92.171.93:8080/UPSRTCServices/UPSRTCService?wsdl'
namespace = 'http://service.upsrtc.trimax.com/'
client = SoapClient(wsdl=url, namespace=namespace, trace=True)
results = client.GetBusTypes()
print results.as_xml()

Upvotes: 1

Related Questions