def get(self, url, headers=None, can_retry=True):
"""
Issue REST GET request to a given URL. Can throw ApiClientError or its subclass.
Arguments:
url (str): API url to fetch a resource from.
headers (dict): Headers necessary as per API, e.g. authorization bearer to perform authorised requests.
can_retry (bool): True if in a case of authentication error it can refresh access token and retry a call.
Returns:
Response in python native data format.
"""
headers_ = {'Authorization': 'Bearer ' + str(self.access_token)}
if headers is not None:
headers_.update(headers)
resp = requests.get(url, headers=headers_)
if resp.status_code == httplib.OK:
return resp.json()
elif resp.status_code == httplib.UNAUTHORIZED and can_retry:
self.access_token = self._refresh_access_token()
return self.get(url, headers, can_retry=False)
else:
raise BrightcoveApiClientError
评论列表
文章目录