From 3d937916976f3da561000f8f62e9e197718cd7ac Mon Sep 17 00:00:00 2001 From: "zhiyi.zeng" Date: Tue, 26 Apr 2022 09:13:17 +1000 Subject: [PATCH 1/3] fixed Celery - TypeError: Object of type bytes is not JSON serializable issue --- jasmin/protocols/rest/tasks.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jasmin/protocols/rest/tasks.py b/jasmin/protocols/rest/tasks.py index ce036205c..fc4d8b1f0 100644 --- a/jasmin/protocols/rest/tasks.py +++ b/jasmin/protocols/rest/tasks.py @@ -102,8 +102,11 @@ def httpapi_send(self, batch_id, batch_config, message_params, config): 'HTTPAPI error: %s' % r.content.strip('"')) else: if batch_config.get('callback_url', None): + resp_content = r.content + if isinstance(resp_content, bytes): + resp_content = str(r.content) batch_callback.delay( - batch_config.get('callback_url'), batch_id, message_params['to'], 1, r.content) + batch_config.get('callback_url'), batch_id, message_params['to'], 1, resp_content) @task(bind=True, base=JasminTask) From c3f4f06e9d9af200d8b65fb9ba2fa25b190dae04 Mon Sep 17 00:00:00 2001 From: "zhiyi.zeng" Date: Tue, 26 Apr 2022 09:33:06 +1000 Subject: [PATCH 2/3] fixed Celery - TypeError: Object of type bytes is not JSON serializable issue --- jasmin/protocols/rest/tasks.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jasmin/protocols/rest/tasks.py b/jasmin/protocols/rest/tasks.py index fc4d8b1f0..a1d8464c1 100644 --- a/jasmin/protocols/rest/tasks.py +++ b/jasmin/protocols/rest/tasks.py @@ -102,9 +102,10 @@ def httpapi_send(self, batch_id, batch_config, message_params, config): 'HTTPAPI error: %s' % r.content.strip('"')) else: if batch_config.get('callback_url', None): - resp_content = r.content - if isinstance(resp_content, bytes): - resp_content = str(r.content) + if isinstance(r.content, bytes) and r.text: + resp_content = r.text + else: + resp_content = r.content batch_callback.delay( batch_config.get('callback_url'), batch_id, message_params['to'], 1, resp_content) From 786900b9e9a1976053676bf7d2424e68b8857bc7 Mon Sep 17 00:00:00 2001 From: "zhiyi.zeng" Date: Tue, 26 Apr 2022 09:43:05 +1000 Subject: [PATCH 3/3] fixed Celery - TypeError: Object of type bytes is not JSON serializable issue --- jasmin/protocols/rest/tasks.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/jasmin/protocols/rest/tasks.py b/jasmin/protocols/rest/tasks.py index a1d8464c1..6b97a9594 100644 --- a/jasmin/protocols/rest/tasks.py +++ b/jasmin/protocols/rest/tasks.py @@ -95,19 +95,15 @@ def httpapi_send(self, batch_id, batch_config, message_params, config): # Return status back if r.status_code != 200: - logger.error('[%s] %s' % (batch_id, r.content.strip('"'))) + logger.error('[%s] %s' % (batch_id, r.text.strip('"'))) if batch_config.get('errback_url', None): batch_callback.delay( batch_config.get('errback_url'), batch_id, message_params['to'], 0, - 'HTTPAPI error: %s' % r.content.strip('"')) + 'HTTPAPI error: %s' % r.text.strip('"')) else: if batch_config.get('callback_url', None): - if isinstance(r.content, bytes) and r.text: - resp_content = r.text - else: - resp_content = r.content batch_callback.delay( - batch_config.get('callback_url'), batch_id, message_params['to'], 1, resp_content) + batch_config.get('callback_url'), batch_id, message_params['to'], 1, r.text) @task(bind=True, base=JasminTask)