1

我对 zeep 和肥皂很陌生。我正在尝试向肥皂 ws 功能发出客户端请求。wsdl的功能:

-<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 中创建任何类型的对象。我努力了 :

    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上,我可以提出请求并成功获得答案:

<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 提出这样的请求。在此先感谢

4

1 回答 1

2

我今天遇到了同样的问题。get_element 方法返回类型。要创建对象,您需要实例化它。你可以这样做:

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

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

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

于 2017-11-02T16:21:42.853 回答