Celery pickle type content disallowed 错误

Celery pickle type content disallowed error

尽管我在 settings.py 中有以下几行:

CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASKS_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
from kombu import serialization
serialization.registry._decoders.pop("application/x-python-serialize")

我仍然收到 pickle 内容不允许的追溯。奇怪的是,我已经让 celery 在另一个地方使用完全相同的设置正常工作。如果有人可以提出解决方案,那将非常有帮助。 Django 版本是 1.7.1,celery 是今天下载的,所以应该是最新的。使用 rabbitmq 作为代理。以下是错误的完整回溯。

[2015-01-01 23:45:20,652: CRITICAL/MainProcess] Can't decode message body: ContentDisallowed('Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)',) [type:u'application/x-python-serialize' encoding:u'binary' headers:{}]
body: '\x80\x02}q\x01(U\x07expiresq\x02NU\x03utcq\x03\x88U\x04argsq\x04X\x04\x00\x00\x00dsgfq\x05\x85q\x06U\x05chordq\x07NU\tcallbacksq\x08NU\x08errbacksq\tNU\x07tasksetq\nNU\x02idq\x0bU263889-0ef2-4193-8286-1a38630df08aq\x0cU\x07retriesq\rK\x00U\x04taskq\x0eU"pricematch.tasks.amazon_pricematchq\x0fU\ttimelimitq\x10NN\x86U\x03etaq\x11NU\x06kwargsq\x12}q\x13u.' (241b)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/kombu/messaging.py", line 586, in _receive_callback
    decoded = None if on_m else message.decode()
  File "/usr/local/lib/python2.7/dist-packages/kombu/message.py", line 142, in decode
    self.content_encoding, accept=self.accept)
  File "/usr/local/lib/python2.7/dist-packages/kombu/serialization.py", line 174, in loads
    raise self._for_untrusted_content(content_type, 'untrusted')
ContentDisallowed: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)

这是我在项目目录中与 settings.py 文件并行的 celery.py 文件中的内容:

from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings')
app = Celery('projectname',broker='amqp://',backend='amqp://',)
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

如果需要更多信息,请告诉我

我相信你正在寻找

CELERY_TASK_SERIALIZER

而不是

CELERY_TASKS_SERIALIZER

celery-task-serializer