<small id='Wd2Bs'></small><noframes id='Wd2Bs'>

<i id='Wd2Bs'><tr id='Wd2Bs'><dt id='Wd2Bs'><q id='Wd2Bs'><span id='Wd2Bs'><b id='Wd2Bs'><form id='Wd2Bs'><ins id='Wd2Bs'></ins><ul id='Wd2Bs'></ul><sub id='Wd2Bs'></sub></form><legend id='Wd2Bs'></legend><bdo id='Wd2Bs'><pre id='Wd2Bs'><center id='Wd2Bs'></center></pre></bdo></b><th id='Wd2Bs'></th></span></q></dt></tr></i><div id='Wd2Bs'><tfoot id='Wd2Bs'></tfoot><dl id='Wd2Bs'><fieldset id='Wd2Bs'></fieldset></dl></div>
  1. <legend id='Wd2Bs'><style id='Wd2Bs'><dir id='Wd2Bs'><q id='Wd2Bs'></q></dir></style></legend>
      <bdo id='Wd2Bs'></bdo><ul id='Wd2Bs'></ul>

    1. <tfoot id='Wd2Bs'></tfoot>

      kombu.exceptions.EncodeError:用户不可JSON序列化

      时间:2024-08-21

      <legend id='gB89E'><style id='gB89E'><dir id='gB89E'><q id='gB89E'></q></dir></style></legend>
      • <bdo id='gB89E'></bdo><ul id='gB89E'></ul>
        <i id='gB89E'><tr id='gB89E'><dt id='gB89E'><q id='gB89E'><span id='gB89E'><b id='gB89E'><form id='gB89E'><ins id='gB89E'></ins><ul id='gB89E'></ul><sub id='gB89E'></sub></form><legend id='gB89E'></legend><bdo id='gB89E'><pre id='gB89E'><center id='gB89E'></center></pre></bdo></b><th id='gB89E'></th></span></q></dt></tr></i><div id='gB89E'><tfoot id='gB89E'></tfoot><dl id='gB89E'><fieldset id='gB89E'></fieldset></dl></div>
          • <tfoot id='gB89E'></tfoot>

            <small id='gB89E'></small><noframes id='gB89E'>

                <tbody id='gB89E'></tbody>

                本文介绍了kombu.exceptions.EncodeError:用户不可JSON序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有Django 1.11.5应用和芹菜4.1.0,我一直收到:

                kombu.exceptions.EncodeError: <User: testuser> is not JSON serializable
                

                我的settings.py:

                CELERY_BROKER_URL = 'amqp://localhost'
                CELERY_RESULT_BACKEND = 'amqp://localhost'
                CELERY_ACCEPT_CONTENT = ['application/json']
                CELERY_RESULT_SERIALIZER = 'json'
                CELERY_TASK_SERIALIZER = 'json'
                CELERY_TIMEZONE = 'Asia/Makassar'
                CELERY_BEAT_SCHEDULE = {}
                

                tasks.py

                from __future__ import absolute_import, unicode_literals
                from celery import task
                from django.contrib.auth.models import User
                
                
                @task(serializer='json')
                def task_number_one():
                    user = User.objects.create(username="testuser", email="test@test.com", password="pass")
                    return user
                

                我在视图中调用任务:

                def form_valid(self, form):
                    form.instance.user = self.request.user
                    task_number_one.delay()
                    return super().form_valid(form)
                

                推荐答案

                该错误是因为当您返回User实例时,芹菜需要来自任务函数的JSON数据。

                如何解决此问题?
                您没有在任何地方使用该返回数据,因此您不必返回它。也就是说,您可以从任务函数中删除return user
                或者
                从任务函数返回Json数据也可以解决此问题

                解决方案%1

                @task(serializer='json')
                def task_number_one():
                    user = User.objects.create(username="testuser", email="test@test.com", password="pass")
                


                解决方案2

                @task(serializer='json')
                
                def task_number_one():
                    user = User.objects.create(username="testuser", email="test@test.com", password="pass")
                    # return some json data instead of `USER` instance
                    return {"status": True}  # Change is here
                

                这篇关于kombu.exceptions.EncodeError:用户不可JSON序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:芹菜即使允许腌制也不接受腌制 下一篇:芹菜:启动时启动任务

                相关文章

                • <bdo id='KUxsy'></bdo><ul id='KUxsy'></ul>
              1. <small id='KUxsy'></small><noframes id='KUxsy'>

                  <tfoot id='KUxsy'></tfoot>
                1. <legend id='KUxsy'><style id='KUxsy'><dir id='KUxsy'><q id='KUxsy'></q></dir></style></legend>
                    <i id='KUxsy'><tr id='KUxsy'><dt id='KUxsy'><q id='KUxsy'><span id='KUxsy'><b id='KUxsy'><form id='KUxsy'><ins id='KUxsy'></ins><ul id='KUxsy'></ul><sub id='KUxsy'></sub></form><legend id='KUxsy'></legend><bdo id='KUxsy'><pre id='KUxsy'><center id='KUxsy'></center></pre></bdo></b><th id='KUxsy'></th></span></q></dt></tr></i><div id='KUxsy'><tfoot id='KUxsy'></tfoot><dl id='KUxsy'><fieldset id='KUxsy'></fieldset></dl></div>