0
我有一个返回以下类型的web服务:为什么Python在SOAP消息中省略了属性?
<xsd:complexType name="TaggerResponse">
<xsd:sequence>
<xsd:element name="msg" type="xsd:string"></xsd:element>
</xsd:sequence>
<xsd:attribute name="status" type="tns:Status"></xsd:attribute>
</xsd:complexType>
类型包含一个元素(msg
)和一个属性(status
)。
为了与Web服务通信,我使用SOAPpy库。下面是一个示例结果恢复由Web服务(SOAP消息):
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:TagResponse>
<parameters status="2">
<msg>text</msg>
</parameters>
</SOAP-ENV:TagResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Python解析此消息:
<SOAPpy.Types.structType parameters at 157796908>: {'msg': 'text'}
正如你所看到的属性都将丢失。我应该怎么做才能得到“status
”的价值?
我想要在消息中的“状态”的值。 `get`方法对结果不起作用:`structType实例没有'get'`的属性。但是,您的回答给了我一个线索,我发现使用`r._getAttr(“status”)`我正在寻找的值。但是,`_getAttr`是一个内部函数,我可以使用它还是有更合适的方法来获取值? – czuk 2009-07-27 15:30:40