首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python - SUDS SOAP无效的命名空间-通道顾问?

Python - SUDS SOAP无效的命名空间-通道顾问?
EN

Stack Overflow用户
提问于 2011-03-02 07:49:30
回答 1查看 1.2K关注 0票数 1

在工作中,我必须访问/使用Channel Advisor API

http://developer.channeladvisor.com/display/cadn/Order+Service

来源:

我正在尝试执行一个简单的ping

代码语言:javascript
复制
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()

问题:

我收到一个响应,指出我的SOAP XML格式不正确

请求需要如下所示:

代码语言:javascript
复制
    <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>

但它看起来却像这样:

代码语言:javascript
复制
    <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>

我完全没有使用SOAP的经验,到目前为止,我一直避免使用它的无休止的实现和复杂性,所以请原谅我的完全无知和缺乏知识,但是如果我做错了什么呢?我如何才能让python (我们选择的这类语言)与通道顾问API一起工作呢?

更新:

*由于我尚未收到任何答复,如果/当我找到解决方案时,我将尝试更新每个人(2011年3月3日)

我认为部分问题是SUDS可能没有正确地包含嵌套的WSDL文件。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-27 09:42:30

我刚刚遇到了同样的问题,最终意识到我必须通过APICredentials让CA响应任何请求,即使是ping。下面是一个例子:

代码语言:javascript
复制
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
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5161842

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档