2012-01-18 125 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

相關問題