python - JsonResponse serialization -
am working on project , when bring in api part receive error " not json serializable"
my tasks.py file looks this
@shared_task def balancequerytask(payload): #rdata = jsonparser().parse(payload) url = 'some url' data = {'organizationid':payload['organizationid'], 'orderid':payload['orderid'], 'operation':payload['operation']} headers = {'content-type':'application/json'} response = requests.post(url, data=json.dumps(data), headers=headers) #convert dict json "json.dumps()" responseobj = response.json() availablebalance = str(int(responseobj['balance']['availablebalance'])/100) if response.status_code == 200: return jsonresponse({'response_code':responseobj['response_code'], 'response_status':responseobj['response_status'], 'availablebalance':availablebalance }) else: return jsonresponse({'response_code':'e2', 'response_status':'failed'}) traceback error
internal server error: /bal traceback (most recent call last): file "/root/projects/paymentgateway/paygate/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner response = get_response(request) file "/root/projects/paymentgateway/paygate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request) file "/root/projects/paymentgateway/paygate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) file "/root/projects/paymentgateway/paygate/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view return view_func(*args, **kwargs) file "/root/projects/paymentgateway/payment/pay/views.py", line 29, in bal response = balancequerytask.delay(data).get() file "/root/projects/paymentgateway/paygate/local/lib/python2.7/site-packages/celery/result.py", line 194, in on_message=on_message, file "/root/projects/paymentgateway/paygate/local/lib/python2.7/site-packages/celery/backends/async.py", line 191, in wait_for_pending return result.maybe_throw(callback=callback, propagate=propagate) file "/root/projects/paymentgateway/paygate/local/lib/python2.7/site-packages/celery/result.py", line 299, in maybe_throw self.throw(value, self._to_remote_traceback(tb)) file "/root/projects/paymentgateway/paygate/local/lib/python2.7/site-packages/celery/result.py", line 292, in throw self.on_ready.throw(*args, **kwargs) file "/root/projects/paymentgateway/paygate/local/lib/python2.7/site-packages/vine/promises.py", line 217, in throw reraise(type(exc), exc, tb) file "", line 1, in reraise encodeerror: not json serializable
Comments
Post a Comment