“缺少身份验证令牌”调用 Amazon SP-API 时的响应

发布于 2025-01-18 23:14:56 字数 1076 浏览 3 评论 0原文

我试图从AMZ SP-API获得成功的回应。以下是我目前的400响应。

我相信问题是标题。 docs 并没有真正说明标题内容需要什么。

当我使用salewever软件包在这里,我能够成功地打电话使用我的AWS和卖方凭证,所以我知道这些工作...

FWIW,我将“商人令牌”用作“ sellerid”路径价值。

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"
    }
  ]
}

I am attempting to get a successful response from the AMZ SP-API. Below is my current 400 response.

I believe the issue is with the headers. The docs here don't really state what the header contents needs to be.

When I use the SaleWeaver package here, I am able to successfully make calls using my AWS and Seller credentials, so I know these work...

FWIW, I am using my 'Merchant Token' as the 'sellerID' PATH value.

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)

response:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揽清风入怀 2025-01-25 23:14:56

标头有 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,则 不需要 签署您的请求。在您的情况下,您必须添加 Authentication 标头(这就是它现在显示缺少令牌的原因)。使用 Auth 标头,请求看起来类似于

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: ...

您可以阅读有关如何计算签名以及如何添加 auth 标头的更多信息 此处

The header has 4 fields without signing:

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

If you use AWS SDK, you don't need to sign your requests. In your case, you'll have to add an Authentication header (which is why it shows missing token right now). With the Auth header, the request looks something like

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: ...

You can read up more on how to calculate the signature and how to add the auth header here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文