Getting error message running Django server
I’m not able to run python manage.py runserver. I was able to run python manage.py migrate successfully. I even changed ASGI_APPLICATION = "MyProject.asgi.application" to ASGI_APPLICATION = "routing.application" which didn’t work. Here is the error I get
show_sunset_warning()
System check identified no issues (0 silenced).
March 28, 2025 - 17:51:56
Django version 5.1.7, using settings 'MyProject.settings'
Starting ASGI/Daphne version 4.1.2 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/daphne/management/commands/runserver.py", line 29, in get_default_application
module = importlib.import_module(path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/home/corey-james/Arborhub/MyProject/MyProject/asgi.py", line 12, in <module>
import arborchat.routing
File "/home/corey-james/Arborhub/MyProject/arborchat/routing.py", line 3, in <module>
from . import consumers
File "/home/corey-james/Arborhub/MyProject/arborchat/consumers.py", line 2, in <module>
from channels.exceptions import StopConsumer
ImportError: cannot import name 'StopConsumer' from 'channels.exceptions' (/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/channels/exceptions.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
self.run()
File "/usr/lib/python3.12/threading.py", line 1012, in run
self._target(*self._args, **self._kwargs)
File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/daphne/management/commands/runserver.py", line 128, in inner_run
application=self.get_application(options),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/daphne/management/commands/runserver.py", line 153, in get_application
return ASGIStaticFilesHandler(get_default_application())
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/daphne/management/commands/runserver.py", line 31, in get_default_application
raise ImproperlyConfigured("Cannot import ASGI_APPLICATION module %r" % path)
django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'MyProject.asgi'
ASGI_APPLICATION = "MyProject.asgi.application"
Rewrite in settings. Py file
since StopConsumer
was removed in django channels v4, you might be using an outdated import. Instead of:
from channels.exceptions import StopConsumer
try removing that line or replacing it with:
from channels.consumer import AsyncConsumer
I fixed it finally, the problem was that Redis wasn't installed