1

I need to realize existing WSDL. I try to inherit my complex type class. But if the derived class implements a xml attribute I get an error. If the derived class doesn't implement xml attribute I get no error.

Is there anything I do wrong? (spyne version '2.12.11', python 2.7.9)

Error:

No handlers could be found for logger "spyne.interface.xml_schema"
Traceback (most recent call last):
  File "/home/leto/workspace/spyne_test/inherited_classes.py", line 32, in <module>
    out_protocol=Soap12())
  File "/usr/local/lib/python2.7/dist-packages/spyne/application.py", line 113, in __init__
    self.in_protocol.set_app(self)
  File "/usr/local/lib/python2.7/dist-packages/spyne/protocol/xml.py", line 368, in set_app
    xml_schema.build_validation_schema()
  File "/usr/local/lib/python2.7/dist-packages/spyne/interface/xml_schema/_base.py", line 223, in build_validation_schema
    self.validation_schema = etree.XMLSchema(etree.parse(f))
  File "xmlschema.pxi", line 90, in lxml.etree.XMLSchema.__init__ (src/lxml/lxml.etree.c:175129)
lxml.etree.XMLSchemaParseError: Element '{http://www.w3.org/2001/XMLSchema}complexType': The content is not valid. Expected is (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))., line 10

Code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from spyne.model.primitive import Unicode
from spyne.server.wsgi import WsgiApplication
from spyne.protocol.soap.soap12 import Soap12
from spyne.model.complex import XmlAttribute, ComplexModel
from spyne import Application, rpc, ServiceBase


ADDRESS = '127.0.0.1'
PORT = 8070


class DeviceEntity(ComplexModel):
    token = XmlAttribute(Unicode, use='required')


class DigitalInput(DeviceEntity):
#     IdleState = Unicode
    IdleState = XmlAttribute(Unicode)


class Service(ServiceBase):

    @rpc(_returns=DigitalInput, _body_style='bare')
    def GetDigitalInput(ctx):
        return DigitalInput()

application = Application([Service], 'some_tns',
                                in_protocol=Soap12(validator='lxml'),
                                out_protocol=Soap12())

wsgi_application = WsgiApplication(application)


if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    server = make_server(ADDRESS, PORT, wsgi_application)
    server.serve_forever()

It's a part of WSDL which I try to implement:

<xs:complexType name="DeviceEntity">
    <xs:annotation>
    <xs:documentation>
        Base class for physical entities like inputs and outputs.
    </xs:documentation>
    </xs:annotation>
    <xs:attribute name="token" type="xs:string" use="required">
    <xs:annotation>
        <xs:documentation>Unique identifier referencing the physical entity.</xs:documentation>
    </xs:annotation>
    </xs:attribute>
</xs:complexType>

<xs:complexType name="DigitalInput">
    <xs:complexContent>
    <xs:extension base="tt:DeviceEntity">
        <xs:sequence>
            <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
            <!--  first ONVIF then Vendor  -->
        </xs:sequence>
        <xs:attribute name="IdleState" type="xs:string">
            <xs:annotation>
                <xs:documentation>Indicate the Digital IdleState status.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:anyAttribute processContents="lax"/>
    </xs:extension>
    </xs:complexContent>
</xs:complexType>

3 Answers3

1

The fix for this bug is now merged to 2.13 mainline.

See: https://github.com/arskom/spyne/pull/493

Burak Arslan
  • 7,671
  • 2
  • 15
  • 24
0

I am having the same problem. I'm glad I'm not the only one to see it.

If you go into your /tmp/ directory you will see the .xsd files that spyne makes that it validates against.

For example, here is one that it generated in my /tmp/ dir.

<xs:schema xmlns:plink="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:s0="http://www.opengis.net/ows/1.1" xmlns:s1="spyne.model.primitive.string" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap11enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap12enc="http://www.w3.org/2003/05/soap-encoding" xmlns:soap12env="http://www.w3.org/2003/05/soap-envelope" xmlns:tns="http://www.opengis.net/sos/2.0" xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" targetNamespace="http://www.opengis.net/sos/2.0" elementFormDefault="qualified">
  <xs:import namespace="http://www.opengis.net/ows/1.1" schemaLocation="s0.xsd"/>
  <xs:complexType name="CapabilitiesType">
    <xs:complexContent>
      <xs:extension base="s0:CapabilitiesBaseType"/>
    </xs:complexContent>
  </xs:complexType>
  <xs:complexType name="GetCapabilitiesType">
    <xs:complexContent>
      <xs:extension base="s0:GetCapabilitiesType"/>
    </xs:complexContent>
    <xs:attribute name="service" type="xs:string"/> <!--HERE-->
  </xs:complexType>
  <xs:element name="Capabilities" type="tns:CapabilitiesType"/>
  <xs:element name="GetCapabilities" type="tns:GetCapabilitiesType"/>
</xs:schema>

It is actually an invalid xsd schema file, and throws that same error when the application runs.

You can see on the line that I highlighted with <!--HERE--> that xs:attribute tag is in the wrong spot. It should be two lines up, inside the xs:extension element, like this:

<xs:complexType name="GetCapabilitiesType">
    <xs:complexContent>
      <xs:extension base="s0:GetCapabilitiesType">
        <xs:attribute name="service" type="xs:string"/> <!--HERE-->
      </xs:extension>
    </xs:complexContent>
</xs:complexType>

Is there a bug report in the spyne git repository regarding this?

Ashley Sommer
  • 337
  • 3
  • 12
0

I found the bug place in code of spyne library which leads to this issue. I changed several code lines in library to solve problem and It helped in my case. I hope it will be usefull for anybody who has the same problem. (I changed spyne library !!! VERSION '2.13.0' !!!)

File path spyne/interface/xml_schema/model.py, complex_add method, this code part (below line number 274):

_ext_elements = dict()
for k,v in deferred:
    ao = v.attribute_of
    if ao is None:
        attribute = etree.Element(XSD('attribute'))
        xml_attribute_add(v, k, attribute, document)
        if cls.Attributes._xml_tag_body_as is None:
            #===============================================================
            # MY HACK
            #===============================================================
            # complex_type.append(attribute) # <-- I just commented out this line
            extension.append(attribute) # <-- and added this line. That's all

        else:
            xtba_ext.append(attribute)
        continue