RC-IamErrorResponse - 查询参数中的帐户上下文与令牌中的帐户上下文不同

RC-IamErrorResponse - Account context in the query param is different from the account context in the token

我正在尝试通过 api 键获取资源组。

首先,我向 IAM 进行身份验证...

apikey = 'myapikeyvalue'

self.log.debug('Authenticating to IAM')
url = self.iam_endpoint + '/identity/token'
data = "apikey={}&grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey".format(apiKey)
headers = { 
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": "Basic Yng6Yng=" 
    }
response = requests.post(url, headers=headers, data=data)
token_type, access_token = # get token_type and access_token from response

然后我收到 account_id ...

url = self.iam_endpoint + '/v1/apikeys/details'
headers = { 
    "IAM-Apikey": apiKey,
    'accept': 'application/json',
    'authorization': '{} {}'.format(token_type, access_token),
    'cache-control': 'no-cache', 
    'content-type': 'application/json'
    }
response = self._request(url=url, http_method='get', description='_get_account_id', additional_headers=headers)
account_id = response.json()['account_id']

接下来,我尝试检索 resource_groups ...

url = self.region.rc_endpoint() + '/v1/resource_groups?account_id=' + account_id
response = self.client._request(url=url, http_method='get', description='get_resource_groups')
return response.json()

但是,这会导致:

{
 "error_code":"RC-IamErrorResponse",
 "message":"Account context in the query param is different from the account context in the token.",
 "status_code":401,
 "transaction_id":"7e89f6873e1bd4f92d57829e0f08f4ad"
}

有什么想法吗?

出于某种原因,返回值的格式似乎是:xxxxxxxxxxxY-YYYY,我们只需要 x。这对我有用

return account_id.split('-')[0][:-1]