python 响应与soapUI 不匹配

标签 python soap wsdl pysimplesoap

当我使用soapUI 访问Web 服务时,我得到了格式正确的文本。 但是当我使用 python 代码时,我得到一个字典,其中所有行都在一个 allBusType 键中。

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 响应中缺少该标记。 Python 输出为所有条目返回一行。

最佳答案

SoapClient返回 SimpleXmlElement如 SoapClient 文档第一行所述:

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

因此,要将其视为 xml,您需要在返回的 SimpleXmlElement 上调用 as_xml 方法。 :

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

以下应该有效:

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

关于python 响应与soapUI 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29392309/

相关文章:

java - Tomcat Web 应用程序不工作

python - 泡沫抛出错误 'type not found' 使用 SOAP 服务

java - 使用 CXF 从 Maven 生成 WSDL2Java

python - py2exe 突然不再工作。没有名为 _view 的模块

java - 如何在eclipse中捕获SOAP消息

php - 无法解析日期时间类型

c# - 如何让 WebClient(web 服务客户端)自动使用默认代理服务器?

python - 将 pandas 数据框保存为图像或 pdf 文档中的表格,并具有良好的多索引显示

python - Django Rest Framework 序列化程序单独呈现表单

python - 类似 cron 的循环任务调度程序设计