回到顶部

阅读目录

celery 报错: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)

出错环境:

  • windows 10
  • python 3.6.8
  • django 1.11.26
  • celery 4.3.0

错误日志:

    同样的代码在 Mac 和 centos 环境下无此错误

[2019-12-16 11:26:23,480: CRITICAL/MainProcess] Can't decode message body: ContentDisallowed('Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)',) [type:'application/x-python-serialize' encoding:'binary' headers:{}]

body: b'\x80\x02}q\x00(X\x04\x00\x00\x00taskq\x01X\x1f\x00\x00\x00apps.share.tasks.post_to_beiqiaq\x02X\x02\x00\x00\x00idq\x03X$\x00\x00\x003f15b89f-23b5-4fae-aeb1-09dc203f4002q\x04X\x04\x00\x00\x00argsq\x05]q\x06X\x06\x00\x00\x00kwargsq\x07}q\x08X\x07\x00\x00\x00retriesq\tK\x00X\x03\x00\x00\x00etaq\nNX\x07\x00\x00\x00expiresq\x0bNX\x03\x00\x00\x00utcq\x0c\x88X\t\x00\x00\x00callbacksq\rNX\x08\x00\x00\x00errbacksq\x0eNX\t\x00\x00\x00timelimitq\x0fNN\x86q\x10X\x07\x00\x00\x00tasksetq\x11NX\x05\x00\x00\x00chordq\x12Nu.' (274b)
Traceback (most recent call last):
  File "e:\py_virtualenv\joyoo\lib\site-packages\celery\worker\consumer\consumer.py", line 546, in on_task_received
    type_ = message.headers['task']                # protocol v2
KeyError: 'task'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "e:\py_virtualenv\joyoo\lib\site-packages\celery\worker\consumer\consumer.py", line 551, in on_task_received
    payload = message.decode()
  File "e:\py_virtualenv\joyoo\lib\site-packages\kombu\message.py", line 193, in decode
    self._decoded_cache = self._decode()
  File "e:\py_virtualenv\joyoo\lib\site-packages\kombu\message.py", line 198, in _decode
    self.content_encoding, accept=self.accept)
  File "e:\py_virtualenv\joyoo\lib\site-packages\kombu\serialization.py", line 253, in loads
    raise self._for_untrusted_content(content_type, 'untrusted')
kombu.exceptions.ContentDisallowed: Refusing to deserialize untrusted content of type pickle (application/x-python-serialize)

解决方法:

settings.py 配置(window 用 pickle 序列化)

# celery 内容等消息的格式设置
if os.name != "nt":
    # Mac and Centos
    CELERY_ACCEPT_CONTENT = ['application/json', ]
    CELERY_TASK_SERIALIZER = 'json'
    # CELERY_RESULT_SERIALIZER = 'json'
else:
    # windows
    CELERY_ACCEPT_CONTENT = ['pickle', ]
    CELERY_TASK_SERIALIZER = 'pickle'
    # CELERY_RESULT_SERIALIZER = 'pickle'

 


^_^
请喝咖啡 ×

文章部分资料可能来源于网络,如有侵权请告知删除。谢谢!

前一篇: Django + celery + redis 执行异步任务及查看结果(推荐)
下一篇: 学习过程的四个阶段