Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
headers = {'PRIVATE-TOKEN': self.token}
if data:
response = self.session.request(method, url, headers=headers, data=data, timeout=10)
elif json:
response = self.session.request(method, url, headers=headers, json=json, timeout=10)
else:
response = self.session.request(method, url, headers=headers, timeout=10)
logging.debug("response code=%s" % response.status_code)
if response.status_code == 404:
raise NotFoundException("Resource path='%s' not found!" % url)
elif response.status_code == 204:
# code calling this function assumes that it can do response.json() so fake it to return empty dict
response.json = lambda: {}
return response
elif not self._is_expected_code(response.status_code, expected_codes):
e = UnexpectedResponseException(
"Request url='%s', method=%s, data='%s' failed "
"- expected code(s) %s, got code %s & body: '%s'" %
(url, method, data,
self._expected_code_to_str(expected_codes), response.status_code, response.content))
e.status_code = response.status_code
raise e
else:
return response