繁体   English   中英

SOAP操作名称:使用Zeep导入

[英]SOAP operation name:import with Zeep

WSDL操作名称: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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM