我想使用picker作为芹菜序列化程序。我收到了一个kombu错误,不允许使用泡菜。
kombu.exceptions.ContentDisallowed: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)当我尝试用.delay提交一个任务时发生异常,这个任务有一个datetime参数。
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:但我不知道如何实现它。
我有过
celeryredis==5.1.2
在我的项目的settings.py中,我尝试过
CELERY_TASK_SERIALIZER = 'pickle'这会导致错误。
(此处未记录此设置,是旧的吗?https://docs.celeryproject.org/en/stable/userguide/configuration.html#task-settings)
这是我试图理解Celery not accepting pickle even after allowing it的celery.py的内容
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()发布于 2021-07-14 14:44:52
因此,这似乎是可行的:
在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中运行。
我这样做是因为datetime参数不知何故不起作用而让它很恼火。我不明白为什么解决方案如此复杂。Django有一个处理datetime的json序列化器。为什么芹菜不能用呢?
https://stackoverflow.com/questions/68372501
复制相似问题