From 4457158ede832e5b86b5d7b91194e30113eb4c5c Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 5 Feb 2013 15:08:48 -0500 Subject: [PATCH] api: Fix running with requests 1.0.x. I would prefer to be testing the attribute itself rather than the version, but it's not easy to access without an actual request object, and I'd prefer to compute this once-and-for-all on startup, rather than on each request, since the latter just seems fragile. (imported from commit dd74cadb1b2359faeb3e1b482faeee4003dfad77) --- humbug/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/humbug/__init__.py b/humbug/__init__.py index 26faf3b..f248302 100644 --- a/humbug/__init__.py +++ b/humbug/__init__.py @@ -38,8 +38,9 @@ __version__ = "0.1.0" # Check that we have a recent enough version # Older versions don't provide the 'json' attribute on responses. assert(requests.__version__ >= '0.12.1') -# And versions in the 1.x series aren't backwards compatible -assert(requests.__version__ < '1.0.0') +# In newer versions, the 'json' attribute is a function, not a property +requests_json_is_function = isinstance(requests.Response.json, property) + API_VERSTRING = "/api/v1/" def generate_option_group(parser): @@ -168,9 +169,13 @@ class Client(object): return {'msg': "Unexpected error:\n%s" % traceback.format_exc(), "result": "unexpected-error"} - if res.json is not None: + if requests_json_is_function: + json_result = res.json() + else: + json_result = res.json + if json_result is not None: end_error_retry(True) - return res.json + return json_result end_error_retry(False) return {'msg': res.text, "result": "http-error", "status_code": res.status_code}