I am trying to write a simple python server using Spyne,
I have gone over the hello world
examples, and now trying to do something a bit more sophisticated. Sadly, there are little to no examples for this (or at least, I couldn't find anything helpful)
I am sending the following XML to the server:
<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>
My server service looks like that: class ExampleService(ServiceBase):
@srpc(String, AnyXml, _returns=None)
def PrintObject(nothing, ObjectA):
print ObjectA
And, trying to follow this question, I have created the following classes (although I am getting the same results without them):
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
Unfortunately, I am getting a weird object which prints this: <Element {my_application_tns}field1 at 0x431bee0>
and while debugging I can't seem to find any children (or whatever I need to go through all of the values).
I do have value1
under the text
field.
I tried to make the function get more AnyXml
parameters, hoping I could read all of them - to no avail.
I also tried other values instead of AnyXml
, such as XmlData
and XmlAttribute
, but it didn't work.
Using XmlAttribute
I got an 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
I got an 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)
.
Any help would be highly appreciated, thanks :)