From 18cefd37a8d382d641a021d19efb4f9ea1500262 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Wed, 7 Nov 2012 17:22:19 -0500 Subject: [PATCH] api: Generically convert non-string values to JSON in python bindings (imported from commit 820bc20d469832b5785b434726c81e59a3f67ea5) --- common.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common.py b/common.py index 8b0471d..465f48e 100644 --- a/common.py +++ b/common.py @@ -27,6 +27,11 @@ class HumbugAPI(): request["api-key"] = self.api_key request["client"] = self.client_name request["failures"] = 0 + + for (key, val) in request.iteritems(): + if not (isinstance(val, str) or isinstance(val, unicode)): + request[key] = simplejson.dumps(val) + while True: try: res = requests.post(urlparse.urljoin(self.base_url, url), data=request, @@ -101,8 +106,7 @@ class HumbugAPI(): return self.do_api_query(request, "/api/v1/get_subscriptions") def subscribe(self, streams): - request = {} - request["streams"] = simplejson.dumps(streams) + request = {'streams': streams} return self.do_api_query(request, "/api/v1/subscribe") def call_on_each_message(self, callback, options = {}):