From d639e0a48599b30777b80c2809ded1efb3a6d926 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 17 Apr 2014 10:04:12 +0200 Subject: add a try/except for older versions of requests they have response.json as a dict instead of response.json() --- test/nagios/support/api.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/nagios/support/api.py b/test/nagios/support/api.py index 3b6a90f..ec1af99 100644 --- a/test/nagios/support/api.py +++ b/test/nagios/support/api.py @@ -17,17 +17,23 @@ class Api(): response = self.session.get(self.api_url(path), verify=self.verify, **args) - return response.json() + return self.parse_json(response) def post(self, path, **args): response = self.session.post(self.api_url(path), verify=self.verify, **args) - return response.json() + return self.parse_json(response) def put(self, path, **args): response = self.session.put(self.api_url(path), verify=self.verify, **args) - return response.json() + return self.parse_json(response) + + def parse_json(self, response): + try: + return response.json() + except TypeError: + return response.json # older versions of requests -- cgit v1.2.3