这个亚马逊商品广告API查询有什么问题
我一直遇到 400 错误请求
。请问有人能告诉我我哪里做错了吗?我不想使用任何库。
from requestmanager import RequestManager
from datetime import datetime
from urllib import quote
dt = quote(datetime.strftime(datetime.utcnow(), '%Y-%m-%d %H:%M:%S'))
sign = quote('mySecretAceessKey')
key = 'myKey'
if __name__ == '__main__':
rP = RequestManager()
url = 'http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId='+key+'&Operation=ItemLookup&ItemId=B003MWJKVI&ResponseGroup=Large&Timestamp='+dt+'&Signature='+ sign
response = rP.getContent(url)
content = response.RESPONSE
我正在按照这里提到的步骤进行操作。
1 个回答
1
你的时间戳变量格式不对。把你创建的链接放到浏览器里,看看返回的xml信息。试着这样来创建你的时间戳:
import time
dt = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
我修正了这个问题后,出现了 HTTPError: HTTP Error 403: Forbidden
的错误。把这个链接放到浏览器里查看,告诉我(还有其他一些我删掉的信息):
... <Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message></Error> ...
我发现从2009年8月17日起,亚马逊要求所有请求他们的产品广告API都必须进行签名。
下面这个链接提供了一种很好的方法来创建所需的链接,去看看吧: http://www.princesspolymath.com/princess_polymath/?p=182