Skip to content

Instantly share code, notes, and snippets.

@restump
Created July 28, 2020 20:51
Show Gist options
  • Save restump/8e2b34f55088d53b966a6beb62af7ba2 to your computer and use it in GitHub Desktop.
Save restump/8e2b34f55088d53b966a6beb62af7ba2 to your computer and use it in GitHub Desktop.
def doHttpRequest(self, verb, url, headers=None, data=None):
options = {}
if headers:
options["headers"] = headers
if data:
options["data"] = data
try:
r = self.http._request(verb.lower(), url, options)
r.raise_for_status()
except requests.exceptions.HTTPError as e:
msg = "request error: {}".format(e)
self.log.error(msg)
self.service_check(self.service_check_name, 2, message=msg, tags=self.tags)
return None
except Exception as e:
msg = "request error: {}".format(e)
self.log.error(msg)
self.service_check(self.service_check_name, 2, message=msg, tags=self.tags)
return None
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment