2014-01-20 117 views
1

我使用下面的API来从亚马逊的订单详情AWS签名不匹配

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 什么是实际的意思?

回答

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

+0

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