AttributeError:'Flask'对象没有属性'user_options' [英] AttributeError: 'Flask' object has no attribute 'user_options'

查看:1136
本文介绍了AttributeError:'Flask'对象没有属性'user_options'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图从下面的文档中设置这个基本的例子:


http://flask.pocoo.org/docs/0.10/patterns/celery/


但到目前为止,我一直得到以下错误:

lockquote
AttributeError:Flask对象没有属性'user_options'

我正在使用celery 3.1.15。
我做了一些在线搜索,但还没有找到正确的答案。
如果有人能说出这点,这将是非常有益的。谢谢


代码:



< pre $ 从芹菜导入芹菜

def make_celery(app):
芹菜= Celery(app.import_name,broker = app.config ['CELERY_BROKER_URL' ])
celery.conf.update(app.config)
TaskBase = celery.Task $ b $ class ContextTask(TaskBase):
abstract = True
def __call __(self ,* args,** kwargs):
with app.app_context():
return TaskBase .__ call __(self,* args,** kwargs)
celery.Task = ContextTask
返回芹菜

示例:

<$ p $从烧瓶导入烧瓶
$ b $ app = Flask(__ name__)
app.config.update(
)CELERY_BROKER_URL ='redis:// localhost:6379 ',
CELERY_RESULT_BACKEND ='redis:// localhost:6379'

celery = make_celery(app)

$ b @ celery.task
def add_together(a,b) :
返回a + b

追溯错误:

  Traceback(最近一次调用的最后一个):
在< module>中,第11行的/ usr / local / bin / celery
sys.exit(main())
文件/usr/local/lib/python2.7/dist-packages/celery/__main__.py,第30行,在主
main ()
文件/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py,第81行,在主
cmd.execute_from_commandline(argv)
文件/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py,第769行,在execute_from_commandline
super(CeleryCommand,self).execute_from_commandline(argv)))
文件/usr/local/lib/python2.7/dist-packages/celery/bin/base.py,第305行,在execute_from_commandline
argv = self.setup_app_from_commandline(argv)
文件/usr/local/lib/python2.7/dist-packages/celery/bin/base.py,第473行,在setup_app_from_commandline
user_preload = tuple(self.app.user_options ['preload']或())
AttributeError:'Flask'对象没有属性'user_options'

更新:
修复了这个问题。我正在运行工作不正确。谢谢大家的帮助

解决方案

我看到原来的问题已经解决的更新,但我没有看到确切的解决方案。为了其他人遇到这个错误,这里是一些更多的信息。

基于瓶芹菜背景任务页面( http://flask.pocoo.org/docs/0.10/patterns/celery/ )建议您启动芹菜:



celery -A your_application worker



假设代码驻留在application.py中,显式指定了这个代码指向芹菜对象(不只是模块名称)避免了错误:
$ b

celery -A application.celery工人


So I am trying to setup this basic example from the following doc:

http://flask.pocoo.org/docs/0.10/patterns/celery/

But so far I keep getting the below error:

AttributeError: 'Flask' object has no attribute 'user_options'

I am using celery 3.1.15. I did some search online but haven't found the correct answer for this. If someone can shed some light on this, that would be really helpful.Thanks

Code:

from celery import Celery

def make_celery(app):
    celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)
    TaskBase = celery.Task
    class ContextTask(TaskBase):
        abstract = True
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return TaskBase.__call__(self, *args, **kwargs)
    celery.Task = ContextTask
    return celery

Example:

from flask import Flask

app = Flask(__name__)
app.config.update(
    CELERY_BROKER_URL='redis://localhost:6379',
    CELERY_RESULT_BACKEND='redis://localhost:6379'
)
celery = make_celery(app)


@celery.task()
def add_together(a, b):
    return a + b

Traceback error:

Traceback (most recent call last):
  File "/usr/local/bin/celery", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 30, in main
    main()
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 81, in main
    cmd.execute_from_commandline(argv)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 769, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 305, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 473, in setup_app_from_commandline
    user_preload = tuple(self.app.user_options['preload'] or ())
AttributeError: 'Flask' object has no attribute 'user_options'

UPDATE: Fixed the issue. I was running the worker incorrectly.Thanks everyone for your help

解决方案

I see the update that the original question has been solved, but I do not see the exact solution. For the sake of others who run into this error, here is some more info.

The Flask Celery Based Background Tasks page (http://flask.pocoo.org/docs/0.10/patterns/celery/) suggests this to start celery:

celery -A your_application worker

The your_application string has to point to your application’s package or module that creates the celery object.

Assuming the code resides in application.py, explicitly pointing to the celery object (not just the module name) avoided the error:

celery -A application.celery worker

这篇关于AttributeError:'Flask'对象没有属性'user_options'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆