如何解决姜戈、芹菜和昆布:如何允许泡菜?
我想使用选择器作为芹菜序列化器。 我收到了不允许使用泡菜的 kombu 错误。
kombu.exceptions.Contentdisallowed: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)
当我尝试使用 .delay
提交任务时发生异常
此任务有一个日期时间参数。
Celery 文档说 (https://docs.celeryproject.org/projects/kombu/en/master/userguide/serialization.html#guide-serialization)
By default Kombu will only load JSON messages,so if you want to use other serialization format you must explicitly enable them in your consumer by using the accept argument:
但我不知道如何实现。
celery[redis]==5.1.2
在我的项目 settings.py 中我已经尝试过
CELERY_TASK_SERIALIZER = 'pickle'
导致错误。
(这里没有记录这个设置,是旧的吗?https://docs.celeryproject.org/en/stable/userguide/configuration.html#task-settings)
这是celery.py
的内容
我试图理解Celery not accepting pickle even after allowing it
from __future__ import absolute_import,unicode_literals
import os
from celery import Celery
from kombu import serialization
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE','project.settings')
app = Celery('project')
# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings',namespace='CELERY')
accept_content = ['pickle','application/x-python-serialize']
task_serializer = 'pickle'
result_serializer = 'pickle'
serialization.register_pickle()
serialization.enable_insecure_serializers()
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
解决方法
所以这似乎有效:
在 settings.py 中
CELERY_BROKER_URL = 'redis://redis:6379/0'
CELERY_RESULT_BACKEND = 'redis://redis:6379/0'
CELERY_TASK_SERIALIZER = 'pickle' # changed,was json
CELERY_ACCEPT_CONTENT = ['json','pickle'] # new
os.environ.setdefault('C_FORCE_ROOT','true') # new
有很多关于我正在做的事情的罪恶的警告。 这是在单租户机器上的 docker 中运行。
我这样做是因为它对日期时间参数以某种方式不起作用感到恼火。我不明白为什么解决方案如此复杂。 Django 有一个处理日期时间的 json 序列化程序。为什么celery不能用?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。