If you use Amazon Associates Web Service, then you may have recently received an email explaining that they are renaming the service to the "Product Advertising API". They're also now requiring you to sign your requests. This was a problem for me. Previously, I was making requests without using an Amazon client library. It's pretty simple to use with just urllib2. However, the logic to sign requests is non-trivial.
I couldn't find any modern Python bindings for the Product Advertising API. However, I knew that boto was a popular client library for some of Amazon's other services like S3 and EC2. I figured the signing logic was probably the same. Even though boto doesn't support the Product Advertising API, I managed to get it to work.
Here's a simple proof of concept. You'll need your own access key, etc.:
I couldn't find any modern Python bindings for the Product Advertising API. However, I knew that boto was a popular client library for some of Amazon's other services like S3 and EC2. I figured the signing logic was probably the same. Even though boto doesn't support the Product Advertising API, I managed to get it to work.
Here's a simple proof of concept. You'll need your own access key, etc.:
import time
import urllib
from boto.connection import AWSQueryConnection
AWS_ACCESS_KEY_ID = '...'
AWS_ASSOCIATE_TAG = '...'
AWS_SECRET_ACCESS_KEY = '...'
search_index = 'All'
keywords = 'pink'
aws_conn = AWSQueryConnection(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY, is_secure=False,
host='ecs.amazonaws.com')
aws_conn.SignatureVersion = '2'
params = dict(
Service='AWSECommerceService',
Version='2008-08-19',
SignatureVersion=aws_conn.SignatureVersion,
AWSAccessKeyId=AWS_ACCESS_KEY_ID,
AssociateTag=AWS_ASSOCIATE_TAG,
Operation='ItemSearch',
SearchIndex=search_index,
Keywords=keywords,
ResponseGroup='ItemAttributes,Images',
Order='salesrank',
Timestamp=time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()))
verb = 'GET'
path = '/onca/xml'
qs, signature = aws_conn.get_signature(params, verb, path)
qs = path + '?' + qs + '&Signature=' + urllib.quote(signature)
print "verb:", verb, "qs:", qs
response = aws_conn._mexe(verb, qs, None, headers={})
print response.read()
Comments
link
i'm a little confused, i'm not crear in the way to get the Associate Tag and how to complete the fields Timestamp and Signature.
there's an example running over there?
Thanks a lot
Diego
You'll have to read Amazon's documentation. It's not that big a deal.
> and how to complete the fields Timestamp and Signature.
The code above does that for you.
> there's an example running over there?
The last I checked, we had this code running in production.
boto.exception.TooManyAuthHandlerReadyToAuthenticate: 6 AuthHandlers ready to authenticate, only 1 expected:
can you help please
http://github.com/yoavaviram/python-amazon-simple-product-api
Its the new kid on the block!