Python - SUDS SOAP 无效的命名空间 - channel 顾问?

标签 python soap suds

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

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

来源:

我正在尝试执行简单的 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()

问题:

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

请求需要如下所示:

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

但它看起来像:

    <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(我们为此类事情选择的语言)与 channel 顾问 API 一起使用

更新:

*由于我还没有收到任何答案,如果/当我找到解决方案时,我会尽力向大家更新(2011 年 3 月 3 日)

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

最佳答案

我刚刚遇到了同样的问题,最后意识到我必须传递 APICredentials 让 CA 响应任何请求,甚至是 ping。这是一个例子:

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

关于Python - SUDS SOAP 无效的命名空间 - channel 顾问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5161842/

相关文章:

python - 当泡沫工作完成时如何向自己发送电子邮件通知?

python - 奇怪的 python 类型 "Text"?

javascript - Python 'is' 与 JavaScript ===

python - 将 2 个不同年份的 .resample(D).size() 绘制到一张图表中?

soap - 通过互连连接到 Epic Medical System

Java WSS4J 证书在签名请求后从 keystore 中消失

python - 完全禁用 SUDS 模式缓存

python - 将 PDF 文件转换为 TXT 文件

python - 如何在 python 中创建 IPortableDeviceManager 的实例?

c# - 使用 PFX 证书发送 HttpWebRequest C#