【发布时间】:2018-04-24 18:27:53
【问题描述】:
我对 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]))
【问题讨论】: