'Missing Auth Token' 调用亚马逊时的响应 SP-API

'Missing Auth Token' Response when calling Amazon SP-API

我正在尝试从 AMZ SP-API 获得成功的响应。以下是我当前的 400 回复。

我认为问题出在 header 上。文档 here 并没有真正说明 header 内容需要是什么。

当我使用 SaleWe​​aver 包 here 时,我能够使用我的 AWS 和卖家凭据成功拨打电话,所以我知道这些工作...

FWIW,我正在使用我的 'Merchant Token' 作为 'sellerID' PATH 值。

import requests
import json

headers = {
  'x-amz-access-token': access,
  'client_id': clientid,
  'client_secret':secret,
  'x-amz-date' : '20220402'
}

payload = {'marketplaceId':'ATVPDKIKX0DER'}

sellerId = merch_token
sku = sku

response = requests.get(
  f'https://sellingpartnerapi-na.amazon.com/listings/2021-08-01/items/{sellerId}/{sku}',
  headers = headers,
  params = payload
)

print(response.text)

回复:

{
  "errors": [
    {
      "message": "Access to requested resource is denied.",
     "code": "MissingAuthenticationToken"
    }
  ]
}

header有4个字段没有签名:

host: sellingpartnerapi-na.amazon.com
user-agent: My Selling Tool/2.0 (Language=Java/1.8.0.221;
Platform=Windows/10)
x-amz-access-token=Atza|IQEBLjAsAhRmHjNgHpi0U-Dme37rR6CuUpSREXAMPLE
x-amz-date: 20190430T123600Z

如果您使用 AWS SDK,您 don't need to sign your requests. In your case, you'll have to add an Authentication header(这就是它现在显示缺少令牌的原因)。使用 Auth header,请求看起来像

Authorization: AWS4-HMAC-SHA256 Credential=AKIAIHV6HIXXXXXXX/20201022/us-east-1/execute-api/aws4_request, SignedHeaders=host;user-agent;x-amz-access-token,
Signature=5d672d79c15b13162d9279b0855cfba6789a8edb4c82c400e06b5924aEXAMPLE
host: sellingpartnerapi-na.amazon.com
user-agent: ...
x-amz-access-token=Atza|IQEBL...
x-amz-date: ...

您可以阅读更多有关如何计算签名以及如何添加身份验证的信息 header here