Python and JSON via Redis does not seem to work -
i having trouble python , json.
1) send dictionary redis via json. use json dump dict on producer , loads consumer:
#this dictionary args = {"last_observed_date": "2014-04-08t02:05:00", "tau": 2, "interval": 5, "backcast": 5, "series": "exr:eur_usd:2014-04-08t02:05:00", "k": 5, "is_difference": false, "m": 3, "is_log": false, "last_time": null, "pair": "eur_usd", "granularity": "minute", "series_name": "closebid", "method": [{"ols": {"alpha": 0.5}}]}
producer server:
args = json.dumps(args) r.lpush(model_queue,args)
consumer server:
args = r.brpop(model_queue,0)[1] args = json.loads(args) traceback (most recent call last): file "/home/ubuntu/workspace/forex-trading/chaos/chaos_worker.py", line 38, in <module> data = json.loads(data) file "/usr/lib/python2.7/json/__init__.py", line 326, in loads return _default_decoder.decode(s) file "/usr/lib/python2.7/json/decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) typeerror: expected string or buffer
my question why, when dump dictionary string, can't decode when retrieved redis?
flow this: dictionary string -> redis -> string dictionary. dump on producer , load on consumer.
you can not pass dictionary json.loads, have pass json string. try:
args = json.loads(json.dumps(args))
Comments
Post a Comment