[英]Celery kombu.exceptions.ContentDisallowed in Docker
我正在使用帶有 fastAPI 的 celery。
在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
使用 kubernetes 中的以下命令啟動 celery。
poetry run 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']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.