【问题标题】:SOAP - Create an element with zeep (python)SOAP - 使用 zeep (python) 创建一个元素
【发布时间】:2016-09-30 12:51:38
【问题描述】:

我必须为项目使用 SOAP API。 对于特定方法,我必须发送一个复杂类型。

这个复杂类型是这样声明的:

<complexType name="specialList">
    <sequence>
        <element name=data" minOccurs="0"maxOccurs="unbounded">
            <complexType>
                <simpleContent>
                    <extension base="string">
                        <attribute name="key" type="string" use="required"/>
                    </extension>
                </simpleContent>
            </complexType>
        </element>
    </sequence>
</complexType>

这是一个例子:

<my_action type="specialList">
    <data key="myKey">MyValue</data>
    <data key="myOtherKey">MyOtherValue</data>
</my_action>

要访问 SOAP API,我使用 zeep(我尝试使用 suds)。 我首先想到的是检索我的“specialList”。

special_list = client.get_type('ns1:specialList')
my_action = special_list(data=[data_1, data_2])

但是我对“数据”类型有疑问。事实上,这种类型的“数据”没有被声明。我不能做 client.get_type("ns1:data")。

我尝试了几次来创建一个简单的元素,但都没有成功。 您知道如何创建这种“特殊”数据吗?

提前,谢谢。

西尔万

【问题讨论】:

    标签: python soap wsdl suds


    【解决方案1】:

    您可以尝试使用他们文档中指出的 AnyObject:http://docs.python-zeep.org/en/master/datastructures.html

    所以在你的代码中:

    从 zeep 导入 xsd

    special_list = client.get_type('ns1:specialList')
    my_action = xsd.AnyObject(special_list, special_list(data=[data_1, data_2]))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多