Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _request_json(self, method, *args, **kwargs):
if 'timeout' not in kwargs:
kwargs['timeout'] = self._timeout
resp = getattr(self._session, method)(*args, **kwargs)
req = args[0].replace(self._baseurl, '')
if resp.status_code == 200:
return self._resp_json(resp, req)
elif resp.status_code == 401:
raise APIRateLimited()
else:
_LOG.error('API returned %i from %s request',
resp.status_code, req)
raise APIError('Unexpected %i response from API' % (
resp.status_code))
def __init__(self):
super(APIRateLimited, self).__init__(
'You are being rate-limited. Try waiting a bit.')