用python zeep创建任何对象 [英] creating any object with python zeep

查看:194
本文介绍了用python zeep创建任何对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的吉普车和肥皂.我试图让客户请求肥皂ws功能. wsdl功能:

i am pretty new to zeep, and soap. i`am trying to make client request to soap ws function. wsdl of function:

-<s:element name="GetRetailTransactions">
    -<s:complexType>
        -<s:sequence>
            -<s:element name="parameters" maxOccurs="1" minOccurs="0">
                -<s:complexType mixed="true">
                      -<s:sequence>
                             <s:any/>
                       </s:sequence>
                </s:complexType>
           </s:element>
       </s:sequence>
    </s:complexType>
</s:element>

我不完全了解如何在zeep中创建任何类型的对象. 我已经尝试过了:

i dont fully understand how to create object with type any in zeep. i have tried :

    wsdl = 'http://domain/app.asmx?WSDL'
    client = Client(wsdl=wsdl)
    params = {

        'RetailTransactionsParameters': {
            'GetNotExportedOnly': '0',
            'GetNotRetrunsOnly': '0',
            'FromDate': '20170518',
            'ToDate': '20170518',
            'TransactionTypeFilter': {
            'TransactionType': '2'
            },
        },
    }
    parameters = client.get_element('ns0:GetRetailTransactions')
    param = xsd.AnyObject(parameters, parameters(params))
    result = client.service.GetRetailTransactions(param)

但是我得到了错误:

File "/home/user/lib/python3.6/site-packages/zeep/xsd/elements/indicators.py", line 227, in render
    if name in value:
TypeError: argument of type 'AnyObject' is not iterable

在soapui上,我可以发出请求并成功获得答案:

on soapui i can make request and successfully get answer with :

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <GetRetailTransactions xmlns="example.com/">
            <parameters>
                <RetailTransactionsParameters>
                    <GetNotExportedOnly>0</GetNotExportedOnly>
                    <GetNotRetrunsOnly>0</GetNotRetrunsOnly>
                    <FromDate>20170518</FromDate>
                    <ToDate>20170518</ToDate>
                    <TransactionTypeFilter>
                     <TransactionType>2</TransactionType>
                    </TransactionTypeFilter>
                </RetailTransactionsParameters>
            </parameters>
        </GetRetailTransactions>
    </Body>
</Envelope>

也许有人可以指导我如何正确使用zeep发出这样的请求. 预先感谢

maybe someone can guide me how to correctly make such a request with zeep.. thanks in advance

推荐答案

我今天遇到了同样的问题. get_element方法返回类型.要创建对象,您需要实例化它.您可以执行以下操作:

I had the same problem today. The get_element method returns the type. To create the object you need to instantiate it. You can either do:

parameters = client.get_element('ns0:GetRetailTransactions')(params)

或者您可以显式设置每个属性:

or you can explicitly set each property:

parameters = client.get_element('ns0:GetRetailTransactions')()
parameters.GetNotExportedOnly = 0
parameters.GetNotRetrunsOnly = 0
...

或者您可以传递dict对象,然后zeep将转换为类型 http://docs.python-zeep.org/en/master/datastructures.html#creating-objects

or you can pass the dict object and zeep does the conversion to the type http://docs.python-zeep.org/en/master/datastructures.html#creating-objects

这篇关于用python zeep创建任何对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆