use*_*912 4 python amazon-mws boto3
我想使用boto3连接到python中的卖家合作伙伴 api 。
assumeRole获取我得到的会话客户端临时凭证的步骤。但不在使用boto3sp-api处理的 aws 服务列表中。是否有与 python 一起使用的参考,或者与 等效的是什么?sp-apis3 = boto3.client('s3')sp-api
我也遇到了像您一样的问题和疑问,我成功连接了,也许这可以帮助:
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})
Run Code Online (Sandbox Code Playgroud)
如果我可以进一步提供帮助,请告诉我:)
| 归档时间: |
|
| 查看次数: |
2695 次 |
| 最近记录: |