gpt4 book ai didi

python - Celery 尝试将代理 URL 作为模块导入?

转载 作者:太空宇宙 更新时间:2023-11-03 14:49:28 30 4
gpt4 key购买 nike

我最近将 Celery 添加到我的后端,但我在下面遇到了这个奇怪的错误

[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 都是相同的,它们包含在亚马逊 AWS 上运行的 redis 实例的 URL。当我尝试运行时

celery worker -A app.celery

在我的项目目录中我收到了这个错误,这是怎么回事?

我设置 celery 的方式是这样的

celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)

最佳答案

您能确认 CELERY_BROKER_PROD 和 CELERY_RESULTS_BACKEND 的值是多少吗?您似乎已将其定义为 myredisserverip.com,但是根据 celery 文档,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://前缀吗?

关于python - Celery 尝试将代理 URL 作为模块导入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46942584/

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