>我最近将芹菜添加到我的后端,但我在下面遇到了这个奇怪的错误
[2017-10-25 21:41:37,142: CRITICAL/MainProcess] Unrecoverable error: ImportError('No module named myredisserverip.com',)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/worker/worker.py", line 203, in start
self.blueprint.start(self)
File "/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py", line 115, in start
self.on_start()
File "/usr/local/lib/python2.7/dist-packages/celery/apps/worker.py", line 143, in on_start
self.emit_banner()
File "/usr/local/lib/python2.7/dist-packages/celery/apps/worker.py", line 158, in emit_banner
' n', self.startup_info(artlines=not use_image))),
File "/usr/local/lib/python2.7/dist-packages/celery/apps/worker.py", line 221, in startup_info
results=self.app.backend.as_uri(),
File "/usr/local/lib/python2.7/dist-packages/kombu/utils/objects.py", line 44, in __get__
value = obj.__dict__[self.__name__] = self.__get(obj)
File "/usr/local/lib/python2.7/dist-packages/celery/app/base.py", line 1183, in backend
return self._get_backend()
File "/usr/local/lib/python2.7/dist-packages/celery/app/base.py", line 901, in _get_backend
self.loader)
File "/usr/local/lib/python2.7/dist-packages/celery/app/backends.py", line 66, in by_url
return by_name(backend, loader), url
File "/usr/local/lib/python2.7/dist-packages/celery/app/backends.py", line 46, in by_name
cls = symbol_by_name(backend, aliases)
File "/usr/local/lib/python2.7/dist-packages/kombu/utils/imports.py", line 56, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named myredisserverip.com
我的 config.py 看起来像这样
class BaseConfig(object):
""" A base configuration of the app """
DEBUG = False
SERVER_NAME = "my-production-ip"
SECRET_KEY = os.environ['SECRET']
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
SQLALCHEMY_DATABASE_URI = os.environ['SQL_PRODUCTION']
SQLALCHEMY_TRACK_MODIFICATIONS = True
CELERY_BROKER_URL = os.environ['CELERY_BROKER_PROD']
CELERY_RESULT_BACKEND = os.environ['CELERY_RESULT_BACKEND_PROD']
DATABASE_CONNECT_OPTIONS = {}
THREADS_PER_PAGE = 2
CSRF_ENABLED = True
CSRF_SESSION_KEY = "secret"
MAIL_SERVER = "smtp.gmail.com"
MAIL_PORT = 465
MAIL_USE_SSL = True
MAIL_USE_TSL = False
MAIL_USERNAME = "blabla"
MAIL_PASSWORD = "pwd"
CELERY_BROKER_PROD 和 CELERY_RESULT_BACKEND 都是相同的,它们包含在 Amazon AWS 上运行的 redis 实例 im 的 URL。当我尝试跑步时
celery worker -A app.celery
在我的项目目录中,我收到此错误,发生了什么?
我设置芹菜的方式是这样的
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
你能确认CELERY_BROKER_PROD和CELERY_RESULTS_BACKEND的值是什么吗?您似乎已将其定义为 myredisserverip.com,但是根据芹菜文档,Redis 服务器应定义为:
CELERY_RESULT_BACKEND = 'redis://:password@host:port/db'
根据此处的文档:http://docs.celeryproject.org/en/3.1/configuration.html#redis-backend-settings
对于您需要定义传输broker_url,可以在此处找到有关此文档的文档:http://docs.celeryproject.org/en/3.1/configuration.html#broker-url
问题是您缺少传输,即环境变量中的 redis://前缀?