python soap suds authenticate to affiliatewindow

时间:2015-08-18 14:10:30

标签: python authentication soap

我尝试使用affiliatewindow - https://www.affiliatewindow.com - api和python。 http://v3.core.com.productserve.com/ProductServeService.wsdl

在文档中:

  

必须在每个请求中发送身份验证SOAP-Header元素。

     

sApiKey(必填)   用户特定密钥用于验证用户(ProductServe API(ShopWindow客户端)密码)   值类型:字符串

但它没有提供此标题外观的任何示例。

我的代码:

from suds.xsd.doctor import ImportDoctor, Import
from suds.client import Client

imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
imp.filter.add('http://v3.core.com.productserve.com/')
d = ImportDoctor(imp)
url = 'http://v3.core.com.productserve.com/ProductServeService.wsdl'

client = Client(url, doctor=d) 

ssn =   '<urn:sApiKey>[the-api-key]</urn:sApiKey>'
client.set_options(soapheaders=ssn) 

result = client.service.getMerchantList()
print result

但我得到的结果是:

suds.WebFault: Server raised fault: 'Authentication Failed'

知道如何进行身份验证吗?谢谢!

-----------------解决-------------------------- ------

经过更多研究后,我发现了一个ruby示例,将其翻译为python,这就是解决方案:

auth = client.factory.create('UserAuthentication')
auth.sApiKey = [api-key]
client.set_options(soapheaders=auth)

谢谢!

1 个答案:

答案 0 :(得分:0)

经过更多研究后,我找到了一个ruby示例,将其翻译为python,这就是解决方案:

auth = client.factory.create('UserAuthentication')
auth.sApiKey = [api-key]
client.set_options(soapheaders=auth)