我正在尝试使用 Spyne 编写一个简单的 python 服务器,
我已经过了hello world
示例,现在尝试做一些更复杂的事情。可悲的是,几乎没有任何例子(或者至少,我找不到任何有用的东西)
我将以下 XML 发送到服务器:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ObjectA xmlns="urn:SNSR_STD" ProtocolVersion="Undefined" MessageType="Undefined">
<ObjectB>
<field1>value1</field1>
<field2>value2</field2>
<field3/>
<field4/>
<field5/>
</ObjectB>
</ObjectA>
</s:Body>
</s:Envelope>
我的服务器服务如下所示:
类示例服务(服务基础):
@srpc(String, AnyXml, _returns=None)
def PrintObject(nothing, ObjectA):
print ObjectA
并且,努力追随this https://stackoverflow.com/questions/19514045/how-to-describe-element-attributes-with-spyne问题,我创建了以下类(尽管没有它们我得到相同的结果):
namespace = 'http://www.w3.org/2001/XMLSchema-instance'
class ObjectB(ComplexModel):
__namespace__ = namespace
field1 = XmlAttribute(Unicode)
field2 = XmlAttribute(Unicode)
field3 = XmlAttribute(Unicode)
field4 = XmlAttribute(Unicode)
field5 = XmlAttribute(Unicode)
class ObjectA(ComplexModel):
__namespace__ = namespace
ObjectB = ObjectB
不幸的是,我得到了一个奇怪的对象,它打印了以下内容:<Element {my_application_tns}field1 at 0x431bee0>
在调试时,我似乎找不到任何孩子(或任何我需要检查所有值的东西)。
我有value1
在下面text
field.
我试图让这个功能变得更多AnyXml
参数,希望我能读取所有这些参数 - 但无济于事。
我还尝试了其他值而不是AnyXml
, 例如XmlData
and XmlAttribute
,但没有成功。
Using XmlAttribute
我得到了一个AttributeError: type object 'XmlAttribute' has no attribute 'attribute_of'
from spyne\model\complex.py, line 605, in __init__ a_of = v.attribute_of
.
Using XmlData
我得到了一个AttributeError: type object 'XmlData' has no attribute 'type'
from spyne\model\complex.py, line 119, in resolve_namespace cls.type.resolve_namespace(cls.type, default_ns, tags)
.
任何帮助将不胜感激,谢谢:)