From 3a09d1a5058a1baf80da84686c219f830a04620a Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 7 Feb 2016 15:16:55 +0100 Subject: Raise exception in case of errors Nicer than complaining about an empty result. --- foreman_ansible_inventory.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'foreman_ansible_inventory.py') diff --git a/foreman_ansible_inventory.py b/foreman_ansible_inventory.py index 03c2914..b1c0f19 100755 --- a/foreman_ansible_inventory.py +++ b/foreman_ansible_inventory.py @@ -119,9 +119,11 @@ class ForemanInventory(object): self.args = parser.parse_args() def _get_json(self, url): - return requests.get(url, - auth=HTTPBasicAuth(self.foreman_user, self.foreman_pw), - verify=self.foreman_ssl_verify).json() + ret = requests.get(url, + auth=HTTPBasicAuth(self.foreman_user, self.foreman_pw), + verify=self.foreman_ssl_verify) + ret.raise_for_status() + return ret.json() def _get_hosts(self): return self._get_json("%s/api/v2/hosts" % self.foreman_url)['results'] -- cgit v1.2.3