python响应与soapUI不匹配

2024-10-01 17:35:19 发布

您现在位置:Python中文网/ 问答频道 /正文

当我使用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()

上面的代码返回以下内容:

^{pr2}$

根据下面的屏幕,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输出为所有条目返回一行。在


Tags: 标记comclienthttpnamespacexmlnsbustypesoapui
1条回答
网友
1楼 · 发布于 2024-10-01 17:35:19

SoapClient返回一个^{},如SoapClient文档的第一行所述:

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

因此,要将其视为xml,需要对返回的^{}调用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()

相关问题 更多 >

    热门问题