2012-01-18 111 views
0

我一直在收到400 Bad Request Error。请任何人都可以告诉我我在这里做错了什么?我不想使用库。亚马逊产品广告API查询有什么问题

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 

我按照提及的步骤here

+0

你为什么不想要使用图书馆? 'boto'是否支持你正在尝试使用的API?这是一个相当成熟的产品。 – dm03514 2012-01-18 14:40:54

+0

库很杂乱,有些需要beautifulSoap一些必需的lxml,lxml需要'vcvarsall.bat',它需要安装Visual Studio 2008.我不希望所有这些混乱。我想做简单的请求。 – 2012-01-18 14:43:51

回答

1

timestamp变量的格式不正确。把你创建的网址放到你的浏览器中,并查看你回来的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的所有请求签名。

以下链接提供了创造必要的URL一个很不错的方法,检查出来:http://www.princesspolymath.com/princess_polymath/?p=182

+0

感谢您的回复。我发现除时间格式之外还有什么问题。 – 2012-01-18 17:45:13

相关问题