Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.authenticator.add_auth(headers)
self.http_conn.request(method, self.root + path, body, headers=headers)
response = self.http_conn.getresponse()
body = response.read().decode('utf-8')
try:
data = json.loads(body)
except ValueError:
data = body
if response.status in [401, 403]:
raise errors.AuthenticationError()
elif response.status == 500:
raise errors.InternalServerError()
elif response.status == 400:
raise errors.BadRequestError(body)
elif response.status == 404:
raise errors.NotFoundError()
return (response, data)