gpt4 book ai didi

python - Docker 中的 Celery kombu.exceptions.ContentDisallowed

转载 作者:行者123 更新时间:2023-12-05 05:36:19 25 4
gpt4 key购买 nike

我正在使用带有 fastAPI 的 celery 。

获取 无法解码消息正文:ContentDisallowed('拒绝反序列化 json 类型的不受信任的内容 (application/json)') 在 docker 中运行时。在没有 docker 的情况下在本地计算机上运行时没有问题。

相同的配置如下。

celery_app = Celery('cda-celery-tasks',
broker=CFG.BROKER_URL,
backend=CFG.BACKEND_URL,
include=['src.tasks.tasks']
)

celery_app.conf.task_serializer = 'pickle'
celery_app.conf.result_serializer = 'pickle'
celery_app.conf.accept_content = ['pickle']
celery_app.conf.enable_utc = True

在 docker 中运行时,我不断收到错误

FROM python:3.8
WORKDIR /app

COPY . .

RUN pip3 install poetry
ENV PATH="/root/.poetry/bin:$PATH"

RUN poetry install

celery 是使用来自 kubernetes 的以下命令启动的。

诗歌运行 celery -A src.infrastructure.celery_application worker --loglevel=INFO --concurrency 2

运行时不断报错

无法解码消息正文:ContentDisallowed('拒绝反序列化 json 类型的不受信任的内容 (application/json)')

body: '{"method": "enable_events", "arguments": {}, "destination": null, "pattern": null, "matcher": null}' (99b)
Traceback (most recent call last):
File "/root/.cache/pypoetry/virtualenvs/cda-9TtSrW0h-py3.8/lib/python3.8/site-packages/kombu/messaging.py", line 620, in _receive_callback
decoded = None if on_m else message.decode()
File "/root/.cache/pypoetry/virtualenvs/cda-9TtSrW0h-py3.8/lib/python3.8/site-packages/kombu/message.py", line 194, in decode
self._decoded_cache = self._decode()
File "/root/.cache/pypoetry/virtualenvs/cda-9TtSrW0h-py3.8/lib/python3.8/site-packages/kombu/message.py", line 198, in _decode
return loads(self.body, self.content_type,
File "/root/.cache/pypoetry/virtualenvs/cda-9TtSrW0h-py3.8/lib/python3.8/site-packages/kombu/serialization.py", line 242, in loads
raise self._for_untrusted_content(content_type, 'untrusted')
kombu.exceptions.ContentDisallowed: Refusing to deserialize untrusted content of type json (application/json)

有人能告诉我可能的原因和解决方法吗?如果我遗漏了什么,过分强调或低估了某个特定点,请在评论中告诉我。非常感谢您抽出宝贵时间。

最佳答案

使用 accept_content 类型配置 celery_app 似乎可以解决问题:

celery_app.conf.accept_content = ['application/json', 'application/x-python-serialize', 'pickle']

关于python - Docker 中的 Celery kombu.exceptions.ContentDisallowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73320669/

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