Ravdeep Ravdeep - 2 years ago 503
Python Question

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

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


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


from celery import Celery

def make_celery(app):
celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
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


from flask import Flask

app = Flask(__name__)
celery = make_celery(app)

def add_together(a, b):
return a + b

Traceback error:

Traceback (most recent call last):
File "/usr/local/bin/celery", line 11, in <module>
File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 30, in main
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 81, in main
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'

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download