微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

姜戈、芹菜和昆布:如何允许泡菜?

如何解决姜戈、芹菜和昆布:如何允许泡菜?

我想使用选择器作为芹菜序列化器。 我收到了不允许使用泡菜的 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?