eBay SOAP API - 缺少 SOA 操作名称标头
我试图调用 eBay 的 findItemsByKeywords
方法,我得到
服务器引发故障:“缺少 SOA 操作名称标头”
我的代码如下:
from config import *
# url = 'http://developer.ebay.com/webservices/latest/ebaySvc.wsdl'
# url = 'http://svcs.ebay.com/services/search/BestMatchItemDetailsService/v1?wsdl'
url = 'http://developer.ebay.com/webservices/finding/latest/FindingService.wsdl'
from suds.client import Client
import logging
logging.basicConfig()
client = Client(url)
from suds.sax.element import Element
ns1 = ('ns1', 'http://www.ebay.com/marketplace/search/v1/services')
app_id = Element('X-EBAY-API-APP-ID', ns = ns1).setText(EBAY_API_APP_ID)
operation_name = Element('X-EBAY-SOA-OPERATION-NAME', ns = ns1).setText('findItemsByKeywords')
api_version = Element('X-EBAY-API-VERSION', ns = ns1).setText(EBAY_APP_VERSION)
site_id = Element('X-EBAY-API-SITE-ID', ns = ns1).setText(EBAY_API_SITE_ID)
encoding = Element('X-EBAY-API-REQUEST-ENCODING', ns = ns1).setText('SOAP')
service_name = Element('X-EBAY-SOA-SERVICE-NAME', ns = ns1).setText('FindingService')
client.set_options(soapheaders = [app_id, operation_name, api_version, site_id, encoding, service_name])
print client.service.findItemsByKeywords(keywords = 'book')
它打印:
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.ebay.com/marketplace/search/v1/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<ns1:X-EBAY-API-APP-ID>123456-1234-1234-1234-7876b3f33c3</ns1:X-EBAY-API-APP-ID>
<ns1:X-EBAY-SOA-OPERATION-NAME>findItemsByKeywords</ns1:X-EBAY-SOA-OPERATION-NAME>
<ns1:X-EBAY-API-VERSION>721</ns1:X-EBAY-API-VERSION>
<ns1:X-EBAY-API-SITE-ID>0</ns1:X-EBAY-API-SITE-ID>
<ns1:X-EBAY-API-REQUEST-ENCODING>SOAP</ns1:X-EBAY-API-REQUEST-ENCODING>
<ns1:X-EBAY-SOA-SERVICE-NAME>FindingService</ns1:X-EBAY-SOA-SERVICE-NAME>
</SOAP-ENV:Header>
<ns0:Body>
<ns1:findItemsByKeywordsRequest>
<ns1:keywords>book</ns1:keywords>
</ns1:findItemsByKeywordsRequest>
</ns0:Body>
</SOAP-ENV:Envelope>
Traceback (most recent call last):
File "wsdl.py", line 22, in <module>
print client.service.findItemsByKeywords(keywords = 'book')
File "/ebay/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/ebay/suds/client.py", line 602, in invoke
result = self.send(soapenv)
File "/ebay/suds/client.py", line 657, in send
result = self.failed(binding, e)
File "/ebay/suds/client.py", line 712, in failed
r, p = binding.get_fault(reply)
File "/ebay/suds/bindings/binding.py", line 265, in get_fault
raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'Missing SOA operation name header'
I am trying to invoke eBay's findItemsByKeywords
method and I get
Server raised fault: 'Missing SOA operation name header'
My code is following:
from config import *
# url = 'http://developer.ebay.com/webservices/latest/ebaySvc.wsdl'
# url = 'http://svcs.ebay.com/services/search/BestMatchItemDetailsService/v1?wsdl'
url = 'http://developer.ebay.com/webservices/finding/latest/FindingService.wsdl'
from suds.client import Client
import logging
logging.basicConfig()
client = Client(url)
from suds.sax.element import Element
ns1 = ('ns1', 'http://www.ebay.com/marketplace/search/v1/services')
app_id = Element('X-EBAY-API-APP-ID', ns = ns1).setText(EBAY_API_APP_ID)
operation_name = Element('X-EBAY-SOA-OPERATION-NAME', ns = ns1).setText('findItemsByKeywords')
api_version = Element('X-EBAY-API-VERSION', ns = ns1).setText(EBAY_APP_VERSION)
site_id = Element('X-EBAY-API-SITE-ID', ns = ns1).setText(EBAY_API_SITE_ID)
encoding = Element('X-EBAY-API-REQUEST-ENCODING', ns = ns1).setText('SOAP')
service_name = Element('X-EBAY-SOA-SERVICE-NAME', ns = ns1).setText('FindingService')
client.set_options(soapheaders = [app_id, operation_name, api_version, site_id, encoding, service_name])
print client.service.findItemsByKeywords(keywords = 'book')
It prints:
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.ebay.com/marketplace/search/v1/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<ns1:X-EBAY-API-APP-ID>123456-1234-1234-1234-7876b3f33c3</ns1:X-EBAY-API-APP-ID>
<ns1:X-EBAY-SOA-OPERATION-NAME>findItemsByKeywords</ns1:X-EBAY-SOA-OPERATION-NAME>
<ns1:X-EBAY-API-VERSION>721</ns1:X-EBAY-API-VERSION>
<ns1:X-EBAY-API-SITE-ID>0</ns1:X-EBAY-API-SITE-ID>
<ns1:X-EBAY-API-REQUEST-ENCODING>SOAP</ns1:X-EBAY-API-REQUEST-ENCODING>
<ns1:X-EBAY-SOA-SERVICE-NAME>FindingService</ns1:X-EBAY-SOA-SERVICE-NAME>
</SOAP-ENV:Header>
<ns0:Body>
<ns1:findItemsByKeywordsRequest>
<ns1:keywords>book</ns1:keywords>
</ns1:findItemsByKeywordsRequest>
</ns0:Body>
</SOAP-ENV:Envelope>
Traceback (most recent call last):
File "wsdl.py", line 22, in <module>
print client.service.findItemsByKeywords(keywords = 'book')
File "/ebay/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/ebay/suds/client.py", line 602, in invoke
result = self.send(soapenv)
File "/ebay/suds/client.py", line 657, in send
result = self.failed(binding, e)
File "/ebay/suds/client.py", line 712, in failed
r, p = binding.get_fault(reply)
File "/ebay/suds/bindings/binding.py", line 265, in get_fault
raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'Missing SOA operation name header'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 ebay-python,eBay API 的非官方 python 包装器。它非常容易使用并且有效。如果您想使用自己的请求,您还可以查看有关如何构造请求的源代码。
Use ebay-python, unofficial python wrapper for eBay API. It's dead easy to use and it works. You can also see the source code on how to construct the request if you want to use your own.
我在尝试做同样的事情时遇到了一些 vb.net 代码的错误,结果证明我只是使用了错误的 AppID。我使用的是带有沙箱 url 的实时版本,切换它后就没有问题了。
I was getting this error with some vb.net code trying to do the same thing and it turned out to be that I was simply using the wrong AppID. I was using the live one with the sandbox url, switched it and it was fine.
我使用了这段代码并且它有效
I used this code and it works