3

I've followed the channels 2 tutorial, but I'm getting this error after running py manage.py runserver

File "C:\Users\Mach2\AppData\Local\Programs\Python\Python37-32\lib\site-packages\channels\routing.py", line 35, in get_default_application
    raise ImproperlyConfigured("Cannot import ASGI_APPLICATION module %r" % path)
django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'channels_test.routing'

8 Answers8

5

You need to add this line to settings.py file.

ASGI_APPLICATION = "routing.application"

found here: Cannot import ASGI_APPLICATION module while runserver using channels 2

Diogo Rosa
  • 178
  • 1
  • 8
  • 1
    In my settings.py file i have ASGI_APPLICATION = 'channels_test.routing.application', i've tried ASGI_APPLICATION = "routing.application", but i have the same error – Yassine Alikhbari Feb 25 '19 at 13:06
  • channels_test is your app name? Did you added the WSGI_APPLICATION setting? Also channels should come as soon as possible in INSTALLED_APPS. – Diogo Rosa Feb 25 '19 at 14:18
  • yes, channels_test is my project name. in my settings.py i have also WSGI_APPLICATION, and channels is the first in INSTALLED_APPS – Yassine Alikhbari Feb 25 '19 at 15:56
  • Did you installed channels with pip3 and are you running runserver with python 3.7? If yes, then it's a very curious problem. – Diogo Rosa Feb 25 '19 at 16:24
  • 1
    yes i've installed channels with pip3 and i'm running runserver with python 3.7 – Yassine Alikhbari Feb 25 '19 at 17:00
1

I've solved the error, i was using the version 3.0.dev20190127224143 of django, and i solved doing the roll back to the version 2.1.7

1

I have same error because i wrote consumer.py instead of consumers.py by mistake. Then I renamed it to consumers.py and error solved.

Rasim Mammadov
  • 141
  • 1
  • 3
1
  1. put the routing.py in the same level as settings.py.

  2. Ensure there is no error in routing.py. You can check it by replacing the content with

    from channels.routing import ProtocolTypeRouter

    application = ProtocolTypeRouter({ })

and see if it solves.

rjhcnf
  • 762
  • 6
  • 12
0

I had same issue because I wrote a class name in imports of asgi.py file that wasn't defined. Then I removed that undefined class of authentication and the error was fixed.

Please check your defined imports in asgi.py file.

Arti
  • 39
  • 2
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30680472) – l33tHax0r Dec 27 '21 at 16:59
0

for myself it was beacuse of a missing package called whitenoise, after installing via pip everything worked fine

pip install whitenoise

Avin Mathew
  • 336
  • 11
  • 25
0

I solved it changing my version of Django from 4.0.5 to 3.2.5; see: https://docs.djangoproject.com/en/4.0/releases/3.2.5/

Jeff Schaller
  • 2,352
  • 5
  • 23
  • 38
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32083790) – Nol4635 Jun 27 '22 at 17:51
0

It helps to me to mark a directory as a source root in Pycharm

Ju Chi
  • 1