python - Pickle 拒绝使用 celery 报告 ContentDisallowed : Refusing to deserialize untrusted content of type pickle 来序列化内容

标签 python json ssl celery pickle

我正在尝试将一些 python 对象主要是 json 可序列化,除了 datetime.datetime 放在 rabbitmq 队列中,因此使用 pickle 进行序列化。

celery_config 文件:

CELERY_TASK_SERIALIZER = 'pickle'
CELERY_RESULT_SERIALIZER = 'pickle'

它抛出一个异常说:

 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)

This link 建议我进行消息签名,对此我一无所知。

有人可以指导我如何解决吗?

最佳答案

你试过吗,这个:

CELERY_ACCEPT_CONTENT = ['pickle']

如此链接所示 ( http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-accept_content ) 此设置接受序列化程序名称和内容类型的列表,因此您可以将序列化程序或您希望序列化的内容类型列入白名单。

因此,要么执行上述操作,要么使用 SSL 消息签名……这基本上是构建一个 ssh key 对,并使 celery 能够使用您的 key 来获得安全连接。

您可以通过以下方式注册您的“KEY”和“CERTIFICATE”来激活消息签名:

CELERY_SECURITY_KEY = '/etc/ssl/private/worker.key'
CELERY_SECURITY_CERTIFICATE = '/etc/ssl/certs/worker.pem'
CELERY_SECURITY_CERT_STORE = '/etc/ssl/certs/*.pem'
from celery.security import setup_security
setup_security()

至于这些东西的含义……以及它是如何工作的,请参阅: http://www.tldp.org/HOWTO/SSL-Certificates-HOWTO/x64.html

此外,关于如何生成 key (以及启用安全的无密码登录),请参阅: https://help.github.com/articles/generating-ssh-keys/http://mah.everybody.org/docs/ssh以获得其中引用的更一般的链接。

关于python - Pickle 拒绝使用 celery 报告 ContentDisallowed : Refusing to deserialize untrusted content of type pickle 来序列化内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27578235/

相关文章:

python - 如何在python和go语言之间共享变量?

fft.rfft 的 Python 绘图频率

Python字典替换值并保存在字典中

java - 如何使用带有 json 的 Map 从数据库设置 map latlng 值?

javascript - Jquery 如何从我的 json 数组中获取数据

rest - 在 Wso2 应用服务器上启用 https

python - 用其他值替换零序列

arrays - 从 JSON 解析数组内的字典获取数据

javascript - 第一个 XMLHttpRequest 失败但仅在 IE9 上

java - Centos 中的 APNS NetworkIOException SSLHandshake 失败,Java 版本为 1.6.0_37