关于celery的bug解决方法:AttributeError: module 'celery_tasks' has no attribute 'celery'

最近写代码突然出现了关于celery属性出错的问题,在网上查了很久也没有找到解决方法,后来重新检查代码才发现是代码的写错误了。

Bug截图

AttributeError: module 'celery_tasks' has no attribute 'celery'

解决方法

  • 检查代码是否出错:
    错误代码:celery -A celery_tasks worker -l info
    正确代码:celery -A celery_tasks.main worker -l info'
    分析:celery属性是在main文件中,只有执行了main文件才能找到celery属性
    在这里插入图片描述
dkl@dkl-VMware-Virtual-Platform:~/learn/graph/study_celery$ celery -A celery_task worker -I info Usage: celery [OPTIONS] COMMAND [ARGS]... Try 'celery --help' for help. Error: Invalid value for '-A' / '--app': Unable to load celery application. While trying to load the module celery_task the following error occurred: Traceback (most recent call last): File "/home/dkl/learn/env/lib/python3.12/site-packages/celery/app/utils.py", line 389, in find_app found = sym.app ^^^^^^^ AttributeError: module 'celery_task' has no attribute 'app' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/dkl/learn/env/lib/python3.12/site-packages/celery/app/utils.py", line 394, in find_app found = sym.celery ^^^^^^^^^^ AttributeError: module 'celery_task' has no attribute 'celery' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/dkl/learn/env/lib/python3.12/site-packages/celery/app/utils.py", line 383, in find_app sym = symbol_by_name(app, imp=imp) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/dkl/learn/env/lib/python3.12/site-packages/kombu/utils/imports.py", line 64, in symbol_by_name return getattr(module, cls_name) if cls_name else module ^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'celery_task' has no attribute 'celery' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/dkl/learn/env/lib/python3.12/site-packages/celery/bin/celery.py", line 58, in convert return find_app(value) ^^^^^^^^^^^^^^^ File "/home/dkl/learn/env/lib/python3.12/site-packages/celery/app/utils.py", line 401, in find_app return find_app( ^^^^^^^^^ File "/home/dkl/learn/env/lib/python3.12/site-packages/celery/app/utils.py", line 386, in find_app sym = imp(app) ^^^^^^^^ File "/home/dkl/learn/env/lib/python3.12/site-packages/celery/utils/imports.py", line 109, in import_from_cwd return imp(module, package=package) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1387, in _gcd_import File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 935, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 995, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "/home/dkl/learn/graph/study_celery/celery_task/celery.py", line 30, in <module> 'schedule': crontab(seconds=10), ^^^^^^^^^^^^^^^^^^^ File "/home/dkl/learn/env/lib/python3.12/site-packages/celery/schedules.py", line 409, in __init__ super().__init__(**kwargs) TypeError: BaseSchedule.__init__() got an unexpected keyword argument 'seconds'
最新发布
03-28
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值