具有复杂输入的Spyne服务器

时间:2017-11-08 13:12:45

标签: python xml server spyne

我正在尝试使用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>

我的服务器服务看起来像这样: class ExampleService(ServiceBase):

@srpc(String, AnyXml, _returns=None)
def PrintObject(nothing, ObjectA):
    print ObjectA

并且,尝试关注this问题,我创建了以下类(虽然我没有它们得到相同的结果):

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

我试图让函数获得更多AnyXml参数,希望我能阅读所有这些参数 - 但无济于事。 我还尝试了其他值,而不是AnyXml,例如XmlDataXmlAttribute,但它没有用。

使用XmlAttribute我从AttributeError: type object 'XmlAttribute' has no attribute 'attribute_of'获得spyne\model\complex.py, line 605, in __init__ a_of = v.attribute_of。 使用XmlData我从AttributeError: type object 'XmlData' has no attribute 'type'获得spyne\model\complex.py, line 119, in resolve_namespace cls.type.resolve_namespace(cls.type, default_ns, tags)

任何帮助都将受到高度赞赏,谢谢:)

0 个答案:

没有答案
相关问题