【问题标题】:SOAP operation name:import with ZeepSOAP 操作名称:使用 Zeep 导入
【发布时间】: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]))

【问题讨论】:

    标签: python soap wsdl zeep


    【解决方案1】:

    您可以使用getattr() 访问client.service 中的方法

    _import = getattr(client.service, 'import')
    result = _import(product_name)
    

    【讨论】:

    • 非常感谢。你帮了我很多。现在我可以继续了:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多