(keyerror: 'celery_broker_url')

  • Last Update :
  • Techknowledgy :
File "C:\Users\User\path\lib\site-packages\environ\environ.py", line 277, in get_value
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the CELERY_BROKER_URL environment variable

Suggestion : 2

I'm getting this error when I execute the anycodings_cookiecutter-django python manage.py command. ,I already installed cookiecutter with its anycodings_cookiecutter-django requirements but I don't know where to go anycodings_cookiecutter-django from there. ,If you want to use celery, see this anycodings_cookiecutter-django tutorial First step with Django.,When you create user project with anycodings_cookiecutter-django cookiecutter, you must set every anycodings_cookiecutter-django required settings. In this case, it is anycodings_cookiecutter-django celery.

File "C:\Users\User\path\lib\site-packages\environ\environ.py", line 277, in get_value
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the CELERY_BROKER_URL environment variable

Suggestion : 3

How many messages to prefetch at a time multiplied by the number of concurrent processes. The default is 4 (four messages for each process). The default setting is usually a good choice, however – if you have very long running tasks waiting in the queue and you have to start the workers, note that the first worker to start will receive four times the number of messages initially. Thus the tasks may not be fairly distributed to the workers.,In some cases a worker may be killed without proper cleanup, and the worker may have published a result before terminating. This value specifies how long we wait for any missing results before raising a WorkerLostError exception.,The number of periodic tasks that can be called before another database sync is issued. Defaults to 0 (sync based on timing - default of 3 minutes as determined by scheduler.sync_every). If set to 1, beat will call sync after every task message sent.,If propagate is True the chord callback will change state to FAILURE with the exception value set to a ChordError instance containing information about the error and the task that failed. This is the default behavior in Celery 3.1+

# # Broker settings.
BROKER_URL = 'amqp://guest:guest@localhost:5672//'

# List of modules to
import when celery starts.
CELERY_IMPORTS = ('myapp.tasks', )

# # Using the database to store task state and results.
CELERY_RESULT_BACKEND = 'db+sqlite:///results.db'

CELERY_ANNOTATIONS = {
   'tasks.add': {
      'rate_limit': '10/s'
   }
}
CELERY_ANNOTATIONS = {
   'tasks.add': {
      'rate_limit': '10/s'
   }
}
CELERY_ANNOTATIONS = {
   '*': {
      'rate_limit': '10/s'
   }
}
def my_on_failure(self, exc, task_id, args, kwargs, einfo):
   print('Oh no! Task failed: {0!r}'.format(exc))

CELERY_ANNOTATIONS = {
   '*': {
      'on_failure': my_on_failure
   }
}
class MyAnnotate(object):

   def annotate(self, task):
   if task.name.startswith('tasks.'):
   return {
      'rate_limit': '10/s'
   }

CELERY_ANNOTATIONS = (MyAnnotate(), {
   …})
CELERY_RESULT_BACKEND = 'db+scheme://user:password@host:port/dbname'

Suggestion : 4

Python Key Error when setting environment variable in supervisord,Is there a Python shortcut for variable checking and assignment?,Python conditional variable assignment using comparison operators,How do I reference a Django settings variable in my models.py?

You have to save a model object if you make changes to it otherwise it won't reflect.

>>> s.user.profile.needs_review = False >>>
   s.save() >>>
   s.user.profile.needs_review
False

The line below

>>> profile = s.user.profile >>>
   profile.needs_review
True

About the python language resource that allows this behavior, you can check this:
https://docs.python.org/3/library/functions.html#property

class C:
   def __init__(self):
   self._x = None

@property
def x(self):
   ""
"I'm the 'x' property."
""
return self._x

@x.setter
def x(self, value):
   self._x = value

@x.deleter
def x(self):
   del self._x