简体   繁体   中英

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM