What is wrong with this Amazon Product Advertising API query


I am keep getting the 400 Bad Request Error. Please can any one tell me what i am doing wrong here?? I don’t want to use libraries.

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

I am following the steps mention here.

Asked By: Aamir Rind



The format of your timestamp variable is incorrect. Take the url you’ve created, put it in your browser and check out the xml message you get back. Try creating your timestamp like so:

import time
dt = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())

After I corrected for that I was getting HTTPError: HTTP Error 403: Forbidden. Trying the url in the browser tells me (amongst other things that I’ve redacted):

... <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> ...

I found that as of August 17th, 2009, Amazon requires that all requests to their Product Advertising API be signed.

The following link provides a very nice methodology for creating the necessary url, check it out: http://www.princesspolymath.com/princess_polymath/?p=182

Answered By: sgallen
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.