简体   繁体   English

SOAP操作名称:使用Zeep导入

[英]SOAP operation name:import with Zeep

I have a problem with WSDL operation name:import. WSDL操作名称:import出现问题。 It is one of the most important remote operation, that update product list on the remote server. 更新远程服务器上的产品列表是最重要的远程操作之一。

The problem starts when I want to call the method: 当我想调用该方法时,问题就开始了:

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

because the 'import' statement is reserved to the python. 因为'import'语句保留给python。 How to make that calling this method does not interfere with python? 如何使调用此方法不会干扰python?

This code below works fine. 下面的代码可以正常工作。 Maybe someone will use it. 也许有人会使用它。

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]))

You can use getattr() to access methods in client.service 您可以使用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