使用 Python use/sign AWS 产品广告 API 最简单的方法是什么?

What is the simplest way for me to use/sign the AWS Product Advertising API using Python?

我一直在努力尝试不同的方法来正确签署我的请求,以便我可以通过 aws 服务进行检索价格 api 调用。

这是我尝试拨打的电话: https://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_RetrievingPriceInformation.html

一段时间后,我决定最好尽可能使用现有模块,所以我尝试使用: https://github.com/DavidMuller/aws-requests-auth

但是,当我尝试将其更改为与检索价格请求一起使用时,我 运行 遇到了一些问题。有没有办法重写以下代码,或者我应该采取更好的前进道路?

import sys, os, base64, datetime, hashlib, hmac
import requests
from aws_requests_auth.aws_auth import AWSRequestsAuth

associate_tag = "IMA_associate"
access_key = "SLIGHTLYLESSSECRETKEY"
secret_key = "SUPERSECRETKEY"

t = datetime.datetime.utcnow()
amzdate = t.strftime('%Y%m%dT%H%M%SZ')
datestamp = t.strftime('%Y%m%d') # Date w/o time, used in credential scope

auth = AWSRequestsAuth(aws_access_key=access_key,
                       aws_secret_access_key=secret_key,
                       aws_host='http://webservices.amazon.com/onca/xml',
                       aws_region='us-west-1',
                       aws_service='AWSECommerceService')

endpoint = 'http://webservices.amazon.com/onca/xml' \
    + '?AssociateTag=' + associate_tag \
    + '&AWSAccessKeyId=' + access_key \
    + '&IdType=ASIN' \
    + '&ItemId=B00KOKTZLQ' \
    + '&Operation=ItemLookup' \
    + '&ResponseGroup=Offers' \
    + '&Service=AWSECommerceService' \
    # + '&Signature=' + auth \
    + '&Timestamp=' + str(datestamp)


response = requests.get(endpoint, auth=auth)
print(response.content)

我真的很感激我能得到的任何帮助!包括正确方向的一点,这有点超出我的驾驶室。

我找到了一个非常有用的 Python 模块来解决上述问题。

https://github.com/yoavaviram/python-amazon-simple-product-api

此模块使调用亚马逊 api 产品变得极其简单。它缺少 api 提供的一些产品特性,但将它们添加到项目中很容易,我将把所有新信息放在一个 pr 中,希望当有人阅读它时它会准备好访问 api 提供的所有信息。