KeyError: 'use_threading' not letting me runserver - django

I'm new to coding in Python so bear with my errors. I keep encountering this error even when I haven't added anything into the code yet.
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\[Name]\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\[Name]\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(self._args, self._kwargs)
File "C:\Users\[Name]\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\[Name]\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 127, in inner_run
threading = options["use_threading"]
KeyError: 'use_threading'
Note: I did migrations and makemigrations just in case but I still get the same error.

Related

testdriven.io: The Definitive Guide to Celery and Django. Running task from Django shell causes error

I am currently going through 'The Definitive Guide to Celery and Django' course by testdriven.io. I've managed to containerize the whole application. Everything was built correctly and seemed to work just fine, but when I tried to enter the Django shell and run a task, to ensure everything works correctly, the following error appeared.
>>> divide.delay(1, 2)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/kombu/utils/functional.py", line 30, in __call__
return self.__value__
AttributeError: 'ChannelPromise' object has no attribute '__value__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/kombu/connection.py", line 446, in _reraise_as_library_errors
yield
File "/usr/local/lib/python3.10/site-packages/kombu/connection.py", line 433, in _ensure_connection
return retry_over_time(
File "/usr/local/lib/python3.10/site-packages/kombu/utils/functional.py", line 312, in retry_over_time
return fun(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/kombu/connection.py", line 877, in _connection_factory
self._connection = self._establish_connection()
File "/usr/local/lib/python3.10/site-packages/kombu/connection.py", line 812, in _establish_connection
conn = self.transport.establish_connection()
File "/usr/local/lib/python3.10/site-packages/kombu/transport/pyamqp.py", line 201, in establish_connection
conn.connect()
File "/usr/local/lib/python3.10/site-packages/amqp/connection.py", line 323, in connect
self.transport.connect()
File "/usr/local/lib/python3.10/site-packages/amqp/transport.py", line 129, in connect
self._connect(self.host, self.port, self.connect_timeout)
File "/usr/local/lib/python3.10/site-packages/amqp/transport.py", line 184, in _connect
self.sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.10/site-packages/celery/app/task.py", line 425, in delay
return self.apply_async(args, kwargs)
File "/usr/local/lib/python3.10/site-packages/celery/app/task.py", line 575, in apply_async
return app.send_task(
File "/usr/local/lib/python3.10/site-packages/celery/app/base.py", line 788, in send_task
amqp.send_task_message(P, name, message, **options)
File "/usr/local/lib/python3.10/site-packages/celery/app/amqp.py", line 510, in send_task_message
ret = producer.publish(
File "/usr/local/lib/python3.10/site-packages/kombu/messaging.py", line 177, in publish
return _publish(
File "/usr/local/lib/python3.10/site-packages/kombu/connection.py", line 523, in _ensured
return fun(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/kombu/messaging.py", line 186, in _publish
channel = self.channel
File "/usr/local/lib/python3.10/site-packages/kombu/messaging.py", line 209, in _get_channel
channel = self._channel = channel()
File "/usr/local/lib/python3.10/site-packages/kombu/utils/functional.py", line 32, in __call__
value = self.__value__ = self.__contract__()
File "/usr/local/lib/python3.10/site-packages/kombu/messaging.py", line 225, in <lambda>
channel = ChannelPromise(lambda: connection.default_channel)
File "/usr/local/lib/python3.10/site-packages/kombu/connection.py", line 895, in default_channel
self._ensure_connection(**conn_opts)
File "/usr/local/lib/python3.10/site-packages/kombu/connection.py", line 432, in _ensure_connection
with ctx():
File "/usr/local/lib/python3.10/contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "/usr/local/lib/python3.10/site-packages/kombu/connection.py", line 450, in _reraise_as_library_errors
raise ConnectionError(str(exc)) from exc
kombu.exceptions.OperationalError: [Errno 111] Connection refused
I've done a quick research and in most cases it seemed to be a lack of the following lines
from config.celery import app as celery_app
__all__ = ['celery_app']
in the config.__init__.py, but it's clearly not an issue here.
I also double checked whether redis container is up and listening on port 6379.
The only difference between my code and the course code is that I decided to use Poetry package manager instead of requirements.txt file and pip.
At this point I am a little bit confused I'll be thankful for any tip. You can find the whole code below:
https://github.com/Kibraks/django-celery-app

When trying to use a rq worker get rq.exceptions.DeserializationError

When trying to run django-rq worker I keep getting this error
15:35:26 Traceback (most recent call last):
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/rq/job.py", line 249, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/django/db/models/base.py", line 2141, in model_unpickle
model = apps.get_model(*model_id)
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/django/apps/registry.py", line 199, in get_model
self.check_models_ready()
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/django/apps/registry.py", line 141, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/rq/worker.py", line 1026, in perform_job
self.prepare_job_execution(job)
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/rq/worker.py", line 911, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/rq/job.py", line 284, in func_name
self._deserialize_data()
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/rq/job.py", line 252, in _deserialize_data
raise DeserializationError() from e
rq.exceptions.DeserializationError
Traceback (most recent call last):
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/rq/job.py", line 249, in _deserialize_data
self._func_name, self._instance, self._args, self._kwargs = self.serializer.loads(self.data)
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/django/db/models/base.py", line 2141, in model_unpickle
model = apps.get_model(*model_id)
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/django/apps/registry.py", line 199, in get_model
self.check_models_ready()
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/django/apps/registry.py", line 141, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/rq/worker.py", line 1026, in perform_job
self.prepare_job_execution(job)
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/rq/worker.py", line 911, in prepare_job_execution
self.procline(msg.format(job.func_name, job.origin, time.time()))
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/rq/job.py", line 284, in func_name
self._deserialize_data()
File "/home/john/PycharmProjects/api.to/venv/lib/python3.8/site-packages/rq/job.py", line 252, in _deserialize_data
raise DeserializationError() from e
rq.exceptions.DeserializationError
The main issue was that I was trying to run rqworker files instead of python manage.py rqworker files

Trying to run a basic django code. When I run 'python manage.py runserver', I get this:

Just created a project, added app definition in settings.py, and created an app with a urls.py file seperately and tried to include the urls.py file in the main urls.py file that is created by default when we create a project and tried to return a HttpResponse in a seprate file.
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py", line 591, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\threading.py", line 950, in _bootstrap_inner
self.run()
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\threading.py", line 888, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py", line 409, in check
messages.extend(check_resolver(pattern))
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Sujit\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'hello.urls' from 'C:\\Users\\Sujit\\Documents\\CS50\\lecture3\\hello\\urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
I believe the error message is pretty clear:
The included URLconf <module 'hello.urls' from 'C:\Users\Sujit\Documents\CS50\lecture3\hello\urls.py'> does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
Make sure this file contains a variable named urlpatterns, and that you can succesfully import it.

Check User online Django 1.10

Hi trying to do like in example:
How to check whether a user is online in django template?
but when adding
'userprofile.middleware.ActiveUserMiddleware', to MIDDLEWARE_CLASSES
recieving next error:
Unhandled exception in thread started by <function wrapper at 0x7fcf6e0b8668>
Traceback (most recent call last):
File "/home/pavlo/.local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/pavlo/.local/lib/python2.7/site-packages/channels/management/commands/runserver.py", line 40, in inner_run
http_consumer=self.get_consumer(*args, **options),
File "/home/pavlo/.local/lib/python2.7/site-packages/channels/management/commands/runserver.py", line 136, in get_consumer
return StaticFilesConsumer()
File "/home/pavlo/.local/lib/python2.7/site-packages/channels/handler.py", line 332, in __init__
self.handler = self.handler_class()
File "/home/pavlo/.local/lib/python2.7/site-packages/channels/staticfiles.py", line 18, in __init__
super(StaticFilesHandler, self).__init__()
File "/home/pavlo/.local/lib/python2.7/site-packages/channels/handler.py", line 179, in __init__
self.load_middleware()
File "/home/pavlo/.local/lib/python2.7/site-packages/django/core/handlers/base.py", line 82, in load_middleware
mw_instance = middleware(handler)
TypeError: this constructor takes no arguments
Thx for help.
May be someone advise how to make check for online/offline users in Django 1.10
Middlewares have changed in Django 1.10, see this guide how to upgrade them

django localsettings.py giving me error on moving from one localhost to another

I had my website running in django local environment and it was working fine.... But for some reasons i have used localsettings.py file from another localhost system runnig same website... It started giving me 505 error... and when i traced back... following things started appering ....
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 219, in __call__
self.load_middleware()
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 51, in load_middleware
raise exceptions.ImproperlyConfigured('Middleware module "%s" does not define a "%s" class' % (mw_module, mw_classname))
ImproperlyConfigured: Middleware module "django.middleware.csrf" does not define a "CsrfResponseMiddleware" class
[05/Sep/2012 15:33:35] "GET / HTTP/1.1" 500 59
Any help would be helpful
CsrfResponseMiddleware was removed in Django 1.4. You're probably running Django 1.2-1.3 in one environment and Django 1.4-master in the other.