正在处理一个项目,当我引入API部分时,我收到此错误“不是JSON可序列化的”
我的tasks.py文件看起来像这样
@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 from dict to 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'})
追踪错误
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 get 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: is not JSON serializable