![](/img/trans.png)
[英]Python - Suds. How to edit the namespaces of SOAP-ENV:Envelope
[英]Python - SUDS SOAP Invalid namespaces - channel advisor?
在工作中,我必須訪問/使用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(我們為這類事情選擇的語言)與渠道顧問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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.