2015-04-01 24 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()