【问题标题】:AWS signature does not matchAWS 签名不匹配
【发布时间】:2014-02-09 06:08:31
【问题描述】:

我正在使用以下 API 从亚马逊获取订单详情

https://mws.amazonservices.com/Orders/2011-01-01?AWSAccessKeyId=aces key&Action=ListOrderItems&SellerId=seller id&AmazonOrderId=order id&Signature=ZQLpf8vEXAMPLE0iC265pf18n0%3D&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=2014-10-04T18%3A12%3A21.687Z&Version=2011-01-01

但出现以下错误

<ErrorResponse>
     <Error>
           <Type>Sender</Type>
           <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>
     <RequestID>ba13b457-bd7c-4413-b138-b216f887ac68</RequestID>
</ErrorResponse>

这是生成签名的python代码

import hmac

import urllib

from base64 import b64encode

from hashlib import sha256

secret_key = ''

to_sign = """"""

signature=b64encode(hmac.new(secret_key, to_sign, sha256).digest())
request = "%s&Signature=%s" %(to_sign,urllib.quote(signature))

你能告诉我我需要在 to_sign 中提供哪些数据吗? to_sign 到底是什么意思?

【问题讨论】:

    标签: amazon-web-services


    【解决方案1】:

    to_sign 是您希望签名(或散列)的内容,在这种情况下是请求。使用您的密钥对请求进行签名,然后使用此签名发送整个请求,以便亚马逊可以确定您发出的请求是否与您签署的请求匹配。

    在你的情况下应该是(除了使用正确的日期等):

    to_sign = "GET https://mws.amazonservices.com/Orders/2011-01-01?AWSAccessKeyId=aces key&Action=ListOrderItems&SellerId=seller id&AmazonOrderId=order id&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=2014-10-04T18%3A12%3A21.687Z&Version=2011-01-01"
    

    在此处查看文档:http://docs.developer.amazonservices.com/en_US/dev_guide/DG_ClientLibraries.html#DG_OwnClientLibrary__Signatures

    【讨论】:

    • 还是同样的错误。我无法弄清楚我哪里出错了。