简体   繁体   English

sp-api - 卖家伙伴 api python

[英]Sp-api - seller partner api python

I want to connect to the seller partner api in python using boto3 .我想使用boto3 连接到 python 中的卖家合作伙伴 api

The steps assumeRole to get temporary credentials for a session client I get.步骤假设角色为我得到的assumeRole客户端获取临时凭证。 But sp-api is not in the list of aws services to handle with boto3 .但是sp-api不在要使用boto3处理的 aws 服务列表中。 Is there a reference for the sp-api to use with python or what would be the equivalent to s3 = boto3.client('s3') for the sp-api ?是否有sp-api与 python 一起使用的参考,或者与 sp- sp-apis3 = boto3.client('s3')等效的东西是什么?

I had also issues and questions like you have, I managed to connect successfully, maybe this can help:我也有像你一样的问题和疑问,我设法成功连接,也许这可以帮助:

import boto3
# ======== GET AUTH ========
# Credentials for user created following the docs
amw_client = boto3.client(
    'sts',
    aws_access_key_id=self.access_key,
    aws_secret_access_key=self.secret_key,
    region_name=self.region
)
# ROLE created following the docs
# STS assume policy must be included in the role
res = amw_client.assume_role(
    RoleArn='arn:aws:iam::xxxx:role/xxxx',
    RoleSessionName='SellingPartnerAPI'
)

Credentials = res["Credentials"]
AccessKeyId = Credentials["AccessKeyId"]
SecretAccessKey = Credentials["SecretAccessKey"]
SessionToken = Credentials["SessionToken"]

from requests_auth_aws_sigv4 import AWSSigV4

aws_auth = AWSSigV4('execute-api',
                    aws_access_key_id=AccessKeyId,
                    aws_secret_access_key=SecretAccessKey,
                    aws_session_token=SessionToken,
                    region=self.region
                    )

import requests
# ======== GET ACCESS TOKEN ======
body = \
    {
        'grant_type': 'refresh_token',
        'client_id': amazon_app_client_id,
        'refresh_token': amazon_app_refresh_token,
        'client_secret': amazon_app_client_secret
    }

h = {'Content-Type': 'application/json'}
access_token_response = \
    requests.post('https://api.amazon.com/auth/o2/token', json=body, headers=h)
access_token = self.access_token_response.json().get('access_token')


# ======== CONSUME API ========
resp = requests.get(
request_url, auth=aws_auth, headers={'x-amz-access-token': access_token})

Let me know if I can help further:)让我知道我是否可以提供进一步的帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM