2015-04-01 26 views
1

当我使用soapUI访问Web服务时,我得到格式正确的文本。 但是当我使用python代码时,我得到一个包含单个allBusType键中的所有行的字典。python响应与soapUI不匹配

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() 

上述代码返回以下结果:

{'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'},.... 

按照下面的屏幕,是的soapUI返回所有的公共汽车站作为单独的标签。 (并非所有按上述单个标签停止)

<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> 

我会想知道,如果这是蟒蛇问题或服务器问题。

对于每个条目,在python响应中缺少的soapUI响应中都有打开和关闭标记,名为“allBusType”。 Python输出为所有条目返回单行。

+0

您使用的是哪个'pysimplesoap'版本,您是如何安装的?谢谢。 – alecxe 2015-04-04 02:47:40

+0

#版本1.16#!pip安装pysimplesoap – shantanuo 2015-04-04 13:27:55

+0

我不坚持pysimplesoap。任何返回正确输出的模块/脚本(如soapUI响应)都可以。 – shantanuo 2015-04-04 14:10:02

回答

1

SoapClient返回如在SoapClient的文档的第一行表示一个SimpleXmlElement

一个简单的,最小的和功能HTTP SOAP web服务消费者,使用httplib2的用于连接的广告的SimpleXMLElement为XML请求/响应操作。

因此把它当作XML,你需要调用返回的SimpleXmlElementas_xml方法:

as_xml(美丽= FALSE):返回文档的XML表示

以下应该工作:

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()