如何使用pysimplesoap将值传递给wsdl客户端的方法

时间:2015-04-30 07:16:43

标签: python pysimplesoap

from pysimplesoap.client import SoapClient
client = SoapClient(wsdl="https://platform.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc?wsdl")
auth_token = client.ClientLogin(username = 'user', password = 'pass',
                                 applicationKey = 'test')

#I got authenticated here

token=  auth_token['ClientLoginResult']

campaign_client =  SoapClient(wsdl="https://platform.mediamind.com/Eyeblaster.MediaMind.API/V2/CampaignService.svc?wsdl"
                                  ,trace = False)

我想调用下面的简单方法获取联系人定义

Show    
    Parameters  

    Name    Type    Description
    ContactID   Int32   The contact ID. Mandatory field.
    UserSecurityToken   String  Contains a string that uniquely identifies the current Sizmek Trafficking API session. You may retrieve the token after logging into the AuthenticationService

_

Show    
Response    

Name    Type    Description
Contact     ContactInfo     Returns the contact information used by ContactInfo

我相信我无法在这里正确传递参数。 这就是为什么错误的请求形成的原因

test = {'UserSecurityToken' :token,'ContactID' : 1  }
data = campaign_client.GetContact(test )

在WSDL客户端中,我可以看到下面的代码来获取带参数的方法。

def __getattr__(self, attr):
        """Return a pseudo-method that can be called"""
        if not self.services:  # not using WSDL?
            return lambda self=self, *args, **kwargs: self.call(attr, *args, **kwargs)
        else:  # using WSDL:
            return lambda *args, **kwargs: self.wsdl_call(attr, *args, **kwargs)

1 个答案:

答案 0 :(得分:2)

您正尝试从dict解压缩关键字参数,并且您需要使用**kwarg表示法:

data = campaign_client.GetContact(**test)

查看此Python文档页面:Unpacking Argument Lists