def post(self, url, payload, headers=None, can_retry=True):
"""
Issue REST POST request to a given URL. Can throw ApiClientError or its subclass.
Arguments:
url (str): API url to fetch a resource from.
payload (dict): POST data.
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 ' + self.access_token,
'Content-type': 'application/json'
}
if headers is not None:
headers_.update(headers)
resp = requests.post(url, data=payload, headers=headers_)
if resp.status_code in (httplib.OK, httplib.CREATED):
return resp.json()
elif resp.status_code == httplib.UNAUTHORIZED and can_retry:
self.access_token = self._refresh_access_token()
return self.post(url, payload, headers, can_retry=False)
else:
raise BrightcoveApiClientError
评论列表
文章目录