[英]Python - SUDS SOAP Invalid namespaces - channel advisor?
At work I have to access/work with the Channel Advisor API 在工作中,我必须访问/使用Channel Advisor API
http://developer.channeladvisor.com/display/cadn/Order+Service http://developer.channeladvisor.com/display/cadn/Order+Service
I'm attempting to perform a simple ping 我正在尝试执行简单的ping操作
from suds.client import Client
url = 'https://api.channeladvisor.com/ChannelAdvisorAPI/v4/OrderService.asmx?WSDL'
soap_client = Client(url, location='https://api.channeladvisor.com/ChannelAdvisorAPI/v4/OrderService.asmx')
soap_client.set_options(port='OrderServiceSoap')
#Ping the service
ping = soap_client.service.Ping()
I get a response stating that my SOAP XML is malformed 我收到响应,指出我的SOAP XML格式错误
The request needs to look like: 该请求应如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://api.channeladvisor.com/webservices/">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<web:Ping/>
</soapenv:Body>
</soapenv:Envelope>
But Instead it looks like: 但是相反,它看起来像:
<SOAP-ENV:Envelope xmlns:ns0="http://api.channeladvisor.com/webservices/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:Ping/>
</ns1:Body>
</SOAP-ENV:Envelope>
I'm not experienced with SOAP at all, i've avoided its endless implementations and complexities thus far - and so pardon me for my sheer ignorance and lack of knowledge, but what if anything am I doing wrong - how can I get python (our language of choice for this sort of thing) to work with the channel advisor API 我完全没有使用SOAP的经验,到目前为止,我避免了其无休止的实现和复杂性-因此,请原谅我的无知和知识不足,但是如果我做错了怎么办-我怎么能得到python(我们为这类事情选择的语言)与渠道顾问API配合使用
*As I have not received any answers, I'll try to update everyone if/when I find a solution (March 3, 2011) *由于我没有收到任何答案,因此,如果发现解决方案,我将尝试更新所有人(2011年3月3日)
I think part of the problem is SUDS may not be including nested WSDL files correctly. 我认为部分问题是SUDS可能未正确包含嵌套的WSDL文件。
I just had this same problem and finally realized that I had to pass the APICredentials for CA to respond to any request, even a ping. 我只是遇到了同样的问题,最终意识到我必须通过APICredentials才能使CA响应任何请求,甚至是ping。 Here's an example:
这是一个例子:
import logging
from suds.client import Client
# Set logging to DEBUG level to see soap messages
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
# URL for CA WSDL
url='https://api.channeladvisor.com/ChannelAdvisorAPI/v5/AdminService.asmx?WSDL'
# Initialize client - The extra location is required because CA is https
client = Client(url,location='https://api.channeladvisor.com/ChannelAdvisorAPI/v5/AdminService.asmx')
# Set soap headers to include login information
login = client.factory.create('APICredentials')
login.DeveloperKey = 'YOUR_KEY'
login.Password = 'YOUR_PWD'
client.set_options(soapheaders=login)
# Send Ping to CA
result = client.service.Ping()
print result
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.