def get_iam_token(self):
    data = urlencode({'grant_type': 'urn:ibm:params:oauth:grant-type:apikey', 'apikey': self.iam_api_key})
    headers = {'content-type': 'application/x-www-form-urlencoded', 'Accept': 'application/json'}
    res = requests.post(self.iam_auth_endpoint, data=data, headers=headers)
    if (res.status_code != 200):
        raise RuntimeError('Error: http code {} while retrieving IAM token for API key.'.format(res.status_code))
    bearer_response = res.json()
    bearer_token = bearer_response['access_token']
    logger.debug(bearer_token)
    return bearer_token
def get_iam_token(self):
    data = urlencode({'grant_type': 'urn:ibm:params:oauth:grant-type:apikey', 'apikey': self.iam_api_key})
    headers = {'content-type': 'application/x-www-form-urlencoded', 'Accept': 'application/json'}
    res = requests.post(self.iam_auth_endpoint, data=data, headers=headers)
    if (res.status_code != 200):
        raise RuntimeError('Error: http code {} while retrieving IAM token for API key.'.format(res.status_code))
    bearer_response = res.json()
    bearer_token = bearer_response['access_token']
    logger.debug(bearer_token)
    return bearer_token