简体   繁体   English

引发 ConnectionError(self._error_message(e)) kombu.exceptions.OperationalError:连接到 localhost:6379 的错误 111。 拒绝连接

[英]raise ConnectionError(self._error_message(e)) kombu.exceptions.OperationalError: Error 111 connecting to localhost:6379. Connection refused

minimal django/celery/redis is running locally, but when deployed to heroku gives me the following error, when I run on python:最小的 django/celery/redis 在本地运行,但是当我在 python 上运行时,部署到 heroku 时出现以下错误:

 raise ConnectionError(self._error_message(e))
 kombu.exceptions.OperationalError: Error 111 connecting to localhost:6379. Connection     
 refused.

This is my tasks.py file in my application directory:这是我的应用程序目录中的 tasks.py 文件:

   from celery import Celery
   import os

   app = Celery('tasks', broker='redis://localhost:6379/0')

   app.conf.update(BROKER_URL=os.environ['REDIS_URL'],
            CELERY_RESULT_BACKEND=os.environ['REDIS_URL'])

   @app.task
   def add(x, y):
      return x + y

Requirements.txt:要求.txt:

  django
  gunicorn
  django-heroku
  celery
  redis
  celery-with-redis
  django-celery
  kombu

I have set worker dyno to 1. Funny things is i could have sworn it was working before, now it doesnt work for some reason.我已将工人测功机设置为 1。有趣的是,我可以发誓它以前可以工作,但现在由于某种原因它不起作用。

Once, you have a minimal django-celery-redis project setup on local, here is how you deploy it on heroku:曾经,您在本地设置了一个最小的 django-celery-redis项目,下面是在 heroku 上部署它的方法:

  1. Add to your tasks.py:添加到你的tasks.py:

     import os app.conf.update(BROKER_URL=os.environ['REDIS_URL'], CELERY_RESULT_BACKEND=os.environ['REDIS_URL'])
  2. Make sure your requirements.txt is like this:确保您的 requirements.txt 是这样的:

     django gunicorn django-heroku celery redis
  3. Add to your Procfile: "worker: celery worker --app=hello.tasks.app"添加到您的 Procfile:“工人:celery 工人 --app=hello.tasks.app”

  4. Make sure it still runs on local确保它仍然在本地运行

  5. enter into terminal: "export REDIS_URL=redis://"进入终端:“export REDIS_URL=redis://”

  6. run "heroku local&"运行“heroku local&”

  7. run python运行 python

     import hello.tasks hello.tasks.add.delay(1,2)

Should return something like:应该返回类似:

    <AsyncResult: e1debb39-b61c-47bc-bda3-ee037d34a6c4>
  1. "heroku apps:create minimal-django-celery-redis" “heroku 应用程序:创建最小 django-celery-redis”

  2. "heroku addons:create heroku-redis -a minimal-django-celery-redis" “heroku 插件:创建 heroku-redis -a minimum-django-celery-redis”

  3. "git add." “混帐添加。”

  4. "git commit -m "Demo"" "git commit -m "演示""

  5. "git push heroku master" “git push heroku 主”

  6. "heroku open&" “heroku 打开&”

  7. "heroku ps:scale worker=1" “heroku ps:规模工人=1”

  8. "heroku run python" “heroku 运行 python”

     import hello.tasks hello.tasks.add.delay(1, 2)
  9. You should see the task running in the application logs: "heroku logs -t -p worker"您应该会在应用程序日志中看到正在运行的任务:“heroku logs -t -p worker”

This solved it for me, i forgot to import celery in project/ init .py like so这为我解决了,我忘记在 project/ init .py 中导入 celery 像这样

from .celery import app as celery_app

__all__ = ("celery_app",)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法连接到 redis://localhost:6379/0:连接到 localhost:6379 时出现错误 111。 拒绝连接 - Cannot connect to redis://localhost:6379/0: Error 111 connecting to localhost:6379. Connection refused OperationalError,连接到 127.0.0.1:6379 的错误 111。 拒绝连接。 在 heroku 中部署后 - OperationalError, Error 111 connecting to 127.0.0.1:6379. Connection refused. After deploying in heroku 连接到 localhost:6379 时出现错误 111。 连接被拒绝。 姜戈赫鲁库 - Error 111 connecting to localhost:6379. Connection refused. Django Heroku Docker 上的 Redis:连接到 0.0.0.0:6379 时出现错误 111。 拒绝连接 - Redis on Docker: Error 111 connecting to 0.0.0.0:6379. Connection refused redis正在运行,但我得到“错误111连接到localhost:6379。 拒绝连接” - redis is running but I'm getting “Error 111 connecting to localhost:6379. Connection refused” Django + Celery + Redis:kombu.exceptions.OperationalError:[Errno 111] 连接被拒绝 - Django + Celery + Redis: kombu.exceptions.OperationalError: [Errno 111] Connection refused redis.exceptions.ConnectionError:连接到 localhost:6379 时出现错误 97。 协议不支持的地址族 - redis.exceptions.ConnectionError: Error 97 connecting to localhost:6379. Address family not supported by protocol docker-compose + django + redis-错误111连接到127.0.0.1:6379。 拒绝连接 - docker-compose + django + redis - Error 111 connecting to 127.0.0.1:6379. Connection refused NGINX 错误:连接到上游时连接()失败(111:连接被拒绝) - NGINX ERROR :connect() failed (111: Connection refused) while connecting to upstream Django Pytest 使用 rabbitmq 和 celery 拒绝 Kombu Connection [111] - Django Pytest gives Kombu Connection refused[111] using rabbitmq and celery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM