gpt4 book ai didi

python - celery 使用 'application/x-python-serialize' 而不是 `application/json`

转载 作者:太空宇宙 更新时间:2023-11-03 12:02:41 25 4
gpt4 key购买 nike

我正在使用 celery 模块 v。 3.1.25 在 Python 2.7 和 Windows 10 中运行 Celery worker。结果必须以 json 而不是 pickle 编码返回。

问题:当 worker 返回任务结果时,RabbitMQ 管理控制台显示结果为 content_type: application/x-python-serialize。当我们将task_serializerresult_serializeraccept_content设置为时,为什么它仍然是x-python-serialize json?

proj/celery.py

from __future__ import absolute_import, unicode_literals
from celery import Celery

app = Celery('tasks',
broker='amqp://test:test@192.168.1.26:5672//', # running in Win10 VM
backend='amqp://',
task_serializer='json',
result_serializer='json',
accept_content=['application/json'],
include=['proj.tasks'])

proj/tasks.py

from __future__ import absolute_import, unicode_literals
from .celery import app

@app.task
def myTask():
...
return ...

worker 开始使用

celery -A proj worker --loglevel=info

并给出关于 pickle 序列化程序的警告

Starting from version 3.2 Celery will refuse to accept pickle by default.

The pickle serializer is a security concern as it may give attackers
the ability to execute any command. It's important to secure
your broker from unauthorized access when using pickle, so we think
that enabling pickle should require a deliberate action and not be
the default choice.

If you depend on pickle then you should set a setting to disable this
warning and to be sure that everything will continue working
when you upgrade to Celery 3.2::

CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']

You must only enable the serializers that you will actually use.


warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED))

-------------- celery@Y-PC v3.1.25 (Cipater)
---- **** -----
--- * *** * -- Windows-10-10.0.14393
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: tasks:0x40ffeb8
- ** ---------- .> transport: amqp://test:**@192.168.1.26:5672//
- ** ---------- .> results: amqp://
- *** --- * --- .> concurrency: 12 (prefork)
-- ******* ----
--- ***** ----- [queues]
-------------- .> celery exchange=celery(direct) key=celery

最佳答案

将 Celery() 配置参数更改为 accept_content=['json'], 而不是 application/json 是否有帮助?

关于python - celery 使用 'application/x-python-serialize' 而不是 `application/json`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43743286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com