2

我想这是一个普遍的问题,而不是 ebay 特定的问题,但我不确定:我正在尝试向 ebay 开发人员 API 发送 XML 请求以检索 XML 响应。使用 curl 时,一切正常,我收到一个 XML 响应,告诉我缺少哪些 API 密钥(如果我通过 HTTP 标头提供它们,我将获得有效的 XML 结果):

curl -d '<!xml version="1.0" encoding="utf-8"?><findItemsByKeywordsRequest xmlns="http://www.ebay.com/marketplace/search/v1/services"><keywords>harry potter phoenix</keywords></findItemsByKeywordsRequest>' \
http://svcs.sandbox.ebay.com/services/search/FindingService/v1

这导致正确的响应:

<?xml version='1.0' encoding='UTF-8'?>
<ms:errorMessage xmlns:ms="http://www.ebay.com/marketplace/services" xmlns="http://www.ebay.com/marketplace/search/v1/services">
    <error>
        <errorId>2038</errorId>
        <domain>CoreRuntime</domain>
        <severity>Error</severity>
        <category>System</category>
        <message>Missing SOA operation name header</message>
        <subdomain>System</subdomain>
    </error>
</ms:errorMessage>

但是当我尝试使用 Python 时,我只会得到“500 Internal Server error”,无论我制作的示例多么基本。我尝试了两种非常基本的方法:

第一:

serverUrl = 'svcs.sandbox.ebay.com'
xmlparameters = '<!xml version="1.0" encoding="utf-8"?><findItemsByKeywordsRequest xmlns="http://www.ebay.com/marketplace/search/v1/services"><keywords>harry potter phoenix</keywords></findItemsByKeywordsRequest>'

webservice = httplib.HTTP(serverUrl)
webservice.putrequest("POST", "/services/search/FindingService/v1")
webservice.putheader("Host", serverUrl)
webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
webservice.putheader("Content-length", "%d" % len(xmlparameters))
webservice.endheaders()
webservice.send(xmlparameters)

第二(这是我的首选方法):

serverUrl = 'svcs.sandbox.ebay.com'
xmlparameters = '<!xml version="1.0" encoding="utf-8"?><findItemsByKeywordsRequest xmlns="http://www.ebay.com/marketplace/search/v1/services"><keywords>harry potter phoenix</keywords></findItemsByKeywordsRequest>'

connection = httplib.HTTPConnection(serverUrl)
connection.request("POST", '/services/search/FindingService/v1', xmlparameters)

正如您在 CURL 示例中看到的那样,我不发送 API 密钥等并不重要,它应该返回一个 XML 错误响应,而不仅仅是 HTTP 状态代码“500 内部服务器错误”。

有谁看到我的 POST 请求做错了什么?

[编辑] 顺便说一句,使用 URL ValueName API 与 Python 完美配合,但这只是对 URL 的 GET 请求。然而,我更喜欢使用 XML API。但是,如果这不可能,我当然会切换到 ValueName URI。

4

2 回答 2

1

它返回 500 状态和 xml 响应:

>>> connection.request("POST", '/services/search/FindingService/v1', xmlparameters)
>>> resp = connection.getresponse()
>>> resp.status
<<< 500
>>> resp.read()
<<< '<?xml version=\'1.0\' encoding=\'UTF-8\'?><ms:errorMessage xmlns:ms="http://www.ebay.com/marketplace/services" xmlns="http://www.ebay.com/marketplace/search/v1/services"><error><errorId>2038</errorId><domain>CoreRuntime</domain><severity>Error</severity><category>System</category><message>Missing SOA operation name header</message><subdomain>System</subdomain></error></ms:errorMessage>'
于 2011-05-06T18:40:22.710 回答
0

500 响应状态相当通用,无论服务器上抛出什么错误都应该返回。你会考虑使用 CGI trackback 来返回错误信息吗?

http://docs.python.org/library/cgitb.html#module-cgitb

于 2011-05-06T17:51:10.340 回答