gpt4 book ai didi

Django + Celery + Redis(Django+芹菜+Redis)

转载 作者:bug小助手 更新时间:2023-10-25 17:52:44 25 4
gpt4 key购买 nike



I have this settings in my social_media.settings:

我在我的Social_media设置中有此设置:


CELERY_BROKER_URL = "redis://0.0.0.0:6379/0"
CELERY_ACCEPT_CONTENT = ["application/json"]
CELERY_RESULT_SERIALIZER = "json"
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_BACKEND = "redis://0.0.0.0:6379/0"
CELERY_TIMEZONE = "Europe/Kiev"

Also I register in my social_media.init:

我还在我的Social_Media.init中注册:


from .celery import app as celery_app


__all__ = ("celery_app", )

Also I have this celery.py file:

另外,我还有这个celery.py文件:


import os

from celery import Celery

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "social_media.settings")


app = Celery("social_media")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()

And I run redis with docker command:

我用docker命令运行redis:


docker run -d -p 6379:6379 redis

So after I run my django project and my docker, I want to run celery with this command:

因此,在运行Django项目和docker之后,我希望使用以下命令运行芹菜:


celery -A social_media worker -l info

I get this error:

我得到了这个错误:


Traceback (most recent call last):
File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\projects\social-media-api\venv\Scripts\celery.exe\__main__.py", line 7, in <module>
File "d:\projects\social-media-api\venv\lib\site-packages\celery\__main__.py", line 15, in main
sys.exit(_main())
File "d:\projects\social-media-api\venv\lib\site-packages\celery\bin\celery.py", line 236, in
main
return celery(auto_envvar_prefix="CELERY")
File "d:\projects\social-media-api\venv\lib\site-packages\click\core.py", line 1157, in
__call__
return self.main(*args, **kwargs)
File "d:\projects\social-media-api\venv\lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
File "d:\projects\social-media-api\venv\lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "d:\projects\social-media-api\venv\lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "d:\projects\social-media-api\venv\lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "d:\projects\social-media-api\venv\lib\site-packages\click\decorators.py", line 33, in
new_func
return f(get_current_context(), *args, **kwargs)
File "d:\projects\social-media-api\venv\lib\site-packages\celery\bin\base.py", line 134, in
caller
return f(ctx, *args, **kwargs)
File "d:\projects\social-media-api\venv\lib\site-packages\celery\bin\worker.py", line 348, in
worker
worker = app.Worker(
File "d:\projects\social-media-api\venv\lib\site-packages\celery\worker\worker.py", line 98, in
__init__
self.setup_instance(**self.prepare_args(**kwargs))
File "d:\projects\social-media-api\venv\lib\site-packages\celery\worker\worker.py", line 119,
in setup_instance
self._conninfo = self.app.connection_for_read()
File "d:\projects\social-media-api\venv\lib\site-packages\celery\app\base.py", line 818, in
connection_for_read
return self._connection(url or self.conf.broker_read_url, **kwargs)
File "d:\projects\social-media-api\venv\lib\site-packages\celery\app\base.py", line 877, in
_connection
return self.amqp.Connection(
File "d:\projects\social-media-api\venv\lib\site-packages\kombu\connection.py", line 201, in
__init__
if not get_transport_cls(transport).can_parse_url:
File "d:\projects\social-media-api\venv\lib\site-packages\kombu\transport\__init__.py", line
90, in get_transport_cls
_transport_cache[transport] = resolve_transport(transport)
File "d:\projects\social-media-api\venv\lib\site-packages\kombu\transport\__init__.py", line
75, in resolve_transport
return symbol_by_name(transport)
File "d:\projects\social-media-api\venv\lib\site-packages\kombu\utils\imports.py", line 59, in
symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "C:\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "d:\projects\social-media-api\venv\lib\site-packages\kombu\transport\redis.py", line 266,
in <module>
class PrefixedStrictRedis(GlobalKeyPrefixMixin, redis.Redis):
AttributeError: 'NoneType' object has no attribute 'Redis'

how can i fix this because as i understand celery should connect to my container with path 0.0.0.0:6379 but instead of this i have this error

我应该如何修复这个问题,因为我了解到,芹菜应该连接到路径为0.0.0.0:6379的容器,但我得到的错误不是这个


更多回答

upd: i forgot to install redis locally

UPD:我忘了在本地安装Redis

优秀答案推荐
更多回答

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