Amazon Advertising API Product Signature

I'm trying to create a signature for the Amazon ad advertising API, it had a few hours, and I still get 403 - could someone take a quick look at the code and tell me that I'm doing something wrong?

This is the function that I use to create a signature.

def create_signature(service, operation, version, search_index, keywords, associate_tag, time_stamp, access_key): start_string = "GET\n" + \ "webservices.amazon.com\n" + \ "/onca/xml\n" + \ "AWSAccessKeyId=" + access_key + \ "&AssociateTag=" + associate_tag + \ "&Keywords=" + keywords + \ "&Operation=" + operation + \ "&SearchIndex=" + search_index + \ "&Service=" + service + \ "&Timestamp=" + time_stamp + \ "&Version=" + version dig = hmac.new("MYSECRETID", msg=start_string, digestmod=hashlib.sha256).digest() sig = urllib.quote_plus(base64.b64encode(dig).decode()) return sig; 

And this is the function I use to return the string for the query

 def ProcessRequest(request_item): start_string = "http://webservices.amazon.com/onca/xml?" + \ "AWSAccessKeyId=" + request_item.access_key + \ "&AssociateTag=" + request_item.associate_tag + \ "&Keywords=" + request_item.keywords + \ "&Operation=" + request_item.operation + \ "&SearchIndex=" + request_item.search_index + \ "&Service=" + request_item.service + \ "&Timestamp=" + request_item.time_stamp + \ "&Version=" + request_item.version + \ "&Signature=" + request_item.signature return start_string; 

And this is the startup code

 _AWSAccessKeyID = "MY KEY" _AWSSecretKey= "MY SECRET KEY" def ProduceTimeStamp(): time = datetime.datetime.now().isoformat() return time; item = Class_Request.setup_request("AWSECommerceService", "ItemSearch", "2011-08-01", "Books", "harry%20potter", "PutYourAssociateTagHere", ProduceTimeStamp(), _AWSAccessKeyID) item2 = Class_Request.ProcessRequest(item) 

An example of a web request that he spits out that produces at 403 is this: -

 http://webservices.amazon.com/onca/xml?AWSAccessKeyId=AKIAIY4QS5QNDAI2NFLA&AssociateTag=PutYourAssociateTagHere&Keywords=harry%20potter&Operation=ItemSearch&SearchIndex=Books&Service=AWSECommerceService&Timestamp=2015-02-26T23:53:14.330000&Version=2011-08-01&Signature=KpC%2BUsyJcw563LzIgxf7GkYI5IV6EfmC0%2FsH8LuP%2FEk%3D 

There is also a class owner class ClassRequest, which has only a field for each request field

The instructions that I followed are here if anyone is interested: - http://docs.aws.amazon.com/AWSECommerceService/latest/DG/rest-signature.html

I hope someone can help, I'm new to Python and lost a little

+5
source share
3 answers

You can simply use one of the existing solutions.

available from PyPI .

OR

Compare your solution with one of the following: https://bitbucket.org/basti/python-amazon-product-api/src/41529579819c75ff4f03bc93ea4f35137716ebf2/amazonproduct/api.py?at=default#cl-143

Your timestamp, for example, looks a little shorter.

+4
source

Once again check that the timestamp is correct, it should have the format 2015-03-27T15: 10: 17.000Z, and in your example web request it looks like this: 2015-02-26T23: 53: 14.330000

A good tool for checking your links - Amazon signs a helper request: https://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html

+2
source

It worked for me.

 $str = "Service=AWSECommerceService&Operation=ItemSearch&AWSAccessKeyId={Access Key}&Keywords=Harry%20Potter&ResponseGroup=Images%2CItemAttributes%2COffers&SearchIndex=Books&Timestamp=2019-08-11T17%3A51%3A56.000Z"; $ar = explode("&", $str); natsort($ar); $str = "GET webservices.amazon.com /onca/xml "; $str .= implode("&", $ar); $str = urlencode(base64_encode(hash_hmac("sha256",$str,'{Secret Key Here}',true))); http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&Operation=ItemSearch&AWSAccessKeyId={Access Key}&Keywords=Harry%20Potter&ResponseGroup=Images%2CItemAttributes%2COffers&SearchIndex=Books&Timestamp=2019-08-11T17%3A51%3A56.000Z&Signature=$str 

Remember: if you get this error, your AccessKey Id is not registered for the product advertising API. Please use the AccessKey Id obtained after registering at https://affiliate-program.amazon.com/assoc_credentials/home

Go to https://affiliate-program.amazon.com/assoc_credentials/home.

0
source

Source: https://habr.com/ru/post/1214285/


All Articles