【问题标题】:The SECRET_KEY setting must not be empty on Celery worker runCelery worker 运行时的 SECRET_KEY 设置不能为空
【发布时间】:2016-11-11 21:05:11
【问题描述】:

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

现在我想在bku Django 应用程序中使用Celery。但是当我运行工人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']

【问题讨论】:

  • @KevinChristopherHenry 你是对的,设置路径是错误的。我通过了rocket.settings.base,现在 Celery 工作得很好。谢谢你。发表你的答案,我会投票赞成。

标签: python django celery


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-25
    • 2017-10-03
    • 2015-06-09
    • 1970-01-01
    • 2021-06-18
    • 2017-06-04
    • 2014-07-07
    • 1970-01-01
    相关资源
    最近更新 更多