gpt4 book ai didi

python - Celery 工作运行时 SECRET_KEY 设置不能为空

转载 作者:行者123 更新时间:2023-12-01 18:30:24 27 4
gpt4 key购买 nike

Django 版本 1.9.7。

我当前的项目结构是:

vehicles/
├── etl
│   ├── etl
│   ├── manage.py
│   ├── pipeline
│   └── bku
└── web
├── db.sqlite3
├── manage.py
├── profiles
├── projects
├── reverse
├── static
├── templates
├── bku
│   ├── admin.py
│   ├── admin.pyc
│   ├── apps.py
│   ├── migrations
│   ├── models.py
│   ├── static
│   ├── templates
│   ├── tests.py
│   ├── urls.py
│   ├── views.py
│   └── views.pyc
└── rocket
├── celery.py
├── __init__.py
├── settings
│   ├── base.py
│   ├── dev.py
│   ├── __init__.py
│   ├── local.py
│   ├── production.py
│   ├── test.py
├── urls.py
├── wsgi.py

现在我想使用Celerybku Django 应用程序。但是当我运行 worker celery -A rocket worker -l info我收到以下错误 django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty. 。我有SECRET_KEY已定义,并且在尝试 Celery 之前我没有出现此错误。

如何运行工作线程?

rocket/celery.py

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rocket.settings')
app = Celery('rocket')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))

rocket/init.py

from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app

__all__ = ['bku']

最佳答案

错误消息有点误导 - 通常当您看到 ImproperlyConfigured 异常时,这意味着 Django 找不到您的设置文件。

在您的情况下,您将 DJANGO_SETTINGS_MODULE 环境变量设置为 rocket.settings,但从您的目录结构看来,它应该类似于 Rocket.settings.Production.

关于python - Celery 工作运行时 SECRET_KEY 设置不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40532824/

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