diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-02-07 15:16:55 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-02-07 15:45:40 +0100 |
commit | 3a09d1a5058a1baf80da84686c219f830a04620a (patch) | |
tree | d81fababfd5be3e395e918577b2869bbc43b75f7 | |
parent | 9972f3fff005a065ea6ebaee73e9fc66d0cf8961 (diff) |
Raise exception in case of errors
Nicer than complaining about an empty result.
-rwxr-xr-x | foreman_ansible_inventory.py | 8 |
1 files changed, 5 insertions, 3 deletions
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'] |