Zeep 的 SOAP 操作 name:import

SOAP operation name:import with Zeep

我的 WSDL 操作有问题 name:import。它是最重要的远程操作之一,更新远程服务器上的产品列表。

当我想调用方法时出现问题:

client.service.import('ns0:Product_Import', _soapheaders = [header_value])
node = client.service.import(product_name)
                           ^
SyntaxError: invalid syntax

因为'import'语句是保留给python的。如何使调用此方法不干扰 python?

下面这段代码工作正常。说不定会有人用。

from zeep import Client
from zeep import xsd

loginIn = {'username': 'my_username', 'password': 'my_password'}
wsdl_auth = 'http://some-wsdl-service.com/auth/wsdl/'
wsdl_products = 'http://some-wsdl-service.com/products/wsdl/'
header = xsd.Element(
'{http://some-wsdl-service.com/products/wsdl/}Header',
    xsd.ComplexType([
        xsd.Element(
            '{http://some-wsdl-service.com/products/wsdl/}sessionId',
            xsd.String()
       ),
   ])
)
client = Client(wsdl = wsdl_auth)
response = client.service.login(loginIn)
sid = response.sessionId
header_value = header(sessionId = sid)
client = Client(wsdl = wsdl_products)
list_of_products = client.service.get('ns0:Product_List',        
                                      _soapheaders [header_value])
client = Client(wsdl = wsdl_auth)
request_to_end = client.service.logout(_soapheaders=[header_value]))

您可以使用 getattr() 访问 client.service

中的方法
_import = getattr(client.service, 'import')
result = _import(product_name)