wy121221612
六花の勇士
2020-06-04 15:24

python-亚马逊接口签名问题 急!!!

60
  • python

访问亚马逊的接口在签名这里一直提示他们计算的签名于我计算的不符,但是我不知道我操作在哪里出现了问题

以下是签名规则

官方文档

图片说明

图片说明

我的代码

import requests
import datetime
import hashlib
def urlEncode(url):
    url.replace("+","%20")
    url.replace("*","%2A")
    url.replace(":","%3A")
    return url
secretKey = "";
serviceUrl = "https://mws.amazonservices.com/";
data = {
    'AWSAccessKeyId':'',
    'Action':'GetReportCount',
    'MWSAuthToken':'',
    'SellerId':'',
    'SignatureMethod':'HmacSHA256',
    'SignatureVersion':'2',
    'Timestamp':datetime.datetime.utcnow().isoformat(),
    'Version':'2009-01-01',
}
a = "&".join(["{0}={1}".format(k, data[k]) for k in sorted(data)])
a = urlEncode(a)
key = "POST\n"+"mws.amazonservices.com\n"+"/\n"+a
sha256 = hashlib.sha256("t+qpwMTc9sZfW2unRXkhDdVlFoL7pUxKZSs4cXSH".encode("utf-8"))
sha256.update(key.encode("utf-8"))
key = sha256.hexdigest()
import base64
k = str(base64.b64encode(key.encode("utf-8")),"utf-8")
data = {
    'AWSAccessKeyId':'',
    'Action':'GetReportCount',
    'MWSAuthToken':'',
    'SellerId':'',
    "Signature":k,
    'SignatureMethod':'HmacSHA256',
    'SignatureVersion':'2',
    'Timestamp':datetime.datetime.utcnow().isoformat(),
    'Version':'2009-01-01',
}
response = requests.post(serviceUrl,data =data )

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐