AWS签名不匹配

时间:2014-01-20 06:46:17

标签: amazon-web-services

我正在使用以下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实际上意味着什么?

1 个答案:

答案 0 :(得分: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