亚马逊产品广告API签名

我试图为亚马逊产品广告API制作一个签名,并在几个小时后仍然收到403 - 任何人都可以快速查看代码并告诉我我是否做错了?

这是我用来创建签名的功能

def create_signature(service, operation, version, search_index, keywords, associate_tag, time_stamp, access_key):
start_string = "GETn" + 
               "webservices.amazon.comn" + 
               "/onca/xmln" + 
               "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;

这是我用来返回请求字符串的函数

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;

这是运行代码

_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)

它在403中产生的示例网络请求是这样的: -

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

还有一个叫做ClassRequest的持有者类,每个请求字段都有一个字段

我遵循的指示在这里,如果有人感兴趣: - http://docs.aws.amazon.com/AWSECommerceService/latest/DG/rest-signature.html

我希望有人能够帮助,我是Python的新手,并且有点失落


您可以简单地使用现有解决方案之一

  • 宽吻海豚
  • 蟒蛇,亚马逊产品的API
  • 蟒蛇,亚马逊简单产品的API
  • 可从PyPI获得。

    要么

    将您的解决方案与其中一个进行比较:https://bitbucket.org/basti/python-amazon-product-api/src/41529579819c75ff4f03bc93ea4f35137716ebf2/amazonproduct/api.py?at=default#cl-143

    例如,你的时间戳看起来有点短。


    再次检查时间戳是否正确,它应该具有2015-03-27T15:10:17.000Z的格式,并且在您的示例Web请求中,它看起来像:2015-02-26T23:53:14.330000

    尝试链接的好工具是亚马逊的签名请求帮手:https://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html

    链接地址: http://www.djcxy.com/p/39027.html

    上一篇: Amazon Product Advertising API Signature

    下一篇: Request signature does not match signature provided for Amazon AWS using Python