当前位置:  开发笔记 > 编程语言 > 正文

烧瓶中的芹菜:AttributeError:'Flask'对象没有属性'user_options'

如何解决《烧瓶中的芹菜:AttributeError:'Flask'对象没有属性'user_options'》经验,为你挑选了1个好方法。

我尝试从命令行启动Celery worker服务器:

celery -A server application worker --loglevel=info  

代码和文件夹路径:

server.py  
application/controllers/routes.py

server.py

app = Flask(__name__)  
from application.controllers import routes  
app.run(host='127.0.0.1',port=5051,debug=True)

route.py

from flask import Flask,  
from celery import Celery
from server import app 


app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0' 

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

@celery.task()  
def add_together(self, count):  
   return "First success"

@app.route("/queing")  
def testsfunction():    
    count = 1  
    add_together.delay(count)  
    return "cool"

追溯:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/celery", line 11, in 
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/celery/__main__.py", line 30, in main
    main()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/celery/bin/celery.py", line 81, in main
    cmd.execute_from_commandline(argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/celery/bin/celery.py", line 770, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/celery/bin/base.py", line 309, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/celery/bin/base.py", line 477, in setup_app_from_commandline
    user_preload = tuple(self.app.user_options['preload'] or ())
AttributeError: 'Flask' object has no attribute 'user_options'

当我在码头经营芹菜工人时,我收到了这个错误.



1> mehdy..:

用这个命令而不是你的命令运行芹菜:

celery -A application.controllers.routes:celery worker --loglevel=info

这将解决您当前的问题,但是您的代码有很多错误,例如,如果您想在函数内部使用自我参数add_together,则应该声明这样的任务:

@celery.task(bind=True)

推荐阅读
拾味湖
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有