Python spyne-从复杂类型继承时出错,派生类实现了xml属性

Python spyne-从复杂类型继承时出错,派生类实现了xml属性,python,spyne,Python,Spyne,我需要实现现有的WSDL。 我尝试继承我的复杂类型类。 但是如果派生类实现了一个xml属性,我会得到一个错误。 如果派生类未实现xml属性,则不会得到错误 我做错什么了吗? (spyne版本'2.12.11',python 2.7.9) 错误: No handlers could be found for logger "spyne.interface.xml_schema" Traceback (most recent call last): File "/home/leto/worksp

我需要实现现有的WSDL。 我尝试继承我的复杂类型类。 但是如果派生类实现了一个xml属性,我会得到一个错误。 如果派生类未实现xml属性,则不会得到错误

我做错什么了吗? (spyne版本'2.12.11',python 2.7.9)

错误:

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
这是我尝试实现的WSDL的一部分:

<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>

输入和输出等物理实体的基类。
引用物理实体的唯一标识符。
指示数字状态。

我也有同样的问题。我很高兴我不是唯一一个看到它的人

如果您进入
/tmp/
目录,您将看到spyne生成的.xsd文件,并根据这些文件进行验证

例如,这里是它在我的
/tmp/
目录中生成的一个

<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>

spyne git存储库中是否有关于此问题的错误报告?

我在spyne库的代码中找到了导致此问题的错误位置。为了解决这个问题,我在库中修改了几行代码,这对我的案例很有帮助。我希望它对任何有同样问题的人都有用。 (我更改了spyne库!!!版本“2.13.0”!!!)

文件路径spyne/interface/xml\u schema/model.py,
complex\u add
方法,此代码部分(行号274下):

\u ext\u elements=dict()
对于k,v,延迟:
ao=v.属性_
如果ao为无:
attribute=etree.Element(XSD('attribute'))
xml\u属性\u添加(v、k、属性、文档)
如果cls.Attributes.\u xml\u tag\u body\u as为无:
#===============================================================
#我的黑客
#===============================================================

#complex_type.append(attribute)#此错误的修复现在合并到2.13主线


请参阅:

,我希望在下一版本中,spyne不会出现此问题。
<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>
<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>
_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