14

I followed the tutorial in the channels documentation but when I start the server python3 manage.py runserver it gives me this :

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 17, 2022 - 00:13:21
Django version 4.1.2, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

when I expected for it to give me this :

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 17, 2022 - 00:13:21
Django version 4.1.2, using settings 'config.settings'
Starting ASGI/Channels version 3.0.5 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

settings.py

INSTALLED_APPS = [
    'channels',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ...
]

ASGI_APPLICATION = 'config.asgi.application'

asgi.py

import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

application = ProtocolTypeRouter({
    'http': get_asgi_application(),
})

It doesn't give any errors even when I change the ASGI_APPLICATION = 'config.asgi.application to ASGI_APPLICATION = ''.

6 Answers6

27

This could be due to the fact that the Django and channels versions you have used are not compatible Try : channels==3.0.4 and django==4.0.0

Patrick Iradukunda
  • 499
  • 1
  • 5
  • 15
  • 2
    Thanks, worked with Python 3.9. – Shashi Shekhar Nov 01 '22 at 23:40
  • (env4) PS D:\python project\learning django channels\channels> python --version Python 3.9.0 (env4) PS D:\python project\learning django channels\channels> pip freeze asgiref==3.5.2 attrs==22.1.0 autobahn==22.7.1 Automat==22.10.0 cffi==1.15.1 channels==3.0.4 constantly==15.1.0 cryptography==38.0.3 daphne==3.0.2 Django==4.0 hyperlink==21.0.0 idna==3.4 incremental==22.10.0 pyasn1==0.4.8 pyasn1-modules==0.2.8 pycparser==2.21 pyOpenSSL==22.1.0 service-identity==21.1.0 six==1.16.0 sqlparse==0.4.3 Twisted==22.10.0 twisted-iocpsupport==1.0.2 – Amol_G Nov 10 '22 at 05:17
  • txaio==22.2.1 typing-extensions==4.4.0 tzdata==2022.6 zope.interface==5.5.1 (env4) PS D:\python project\learning django channels\channels> – Amol_G Nov 10 '22 at 05:17
  • For above version does not work for me. – Amol_G Nov 10 '22 at 05:18
  • According to the docs I added daphne at the top in the installed apps list. After that running the runserver command starts ASGI/Daphne server. Is it okay to do that? – Ritankar Bhattacharjee Nov 27 '22 at 05:01
  • This was exactly what I needed. Thanks a lot! How did you find out about the compatibility of those versions? I couldn't find information on what channels version is compatible with what django version. Could you point me to a link or something? Thanks again! – Ciprian Stoica Mar 09 '23 at 09:53
  • I don't think downgrading channels or Django just to support ASGI is a good idea thus I went for @reza_khalafi 's answer instead of downgrading Django. – devmike01 Aug 08 '23 at 11:47
  • 4.0.0 doesnt work at all but if you use 3.0.4 it works like a charm! – Berk Efe Keskin Aug 11 '23 at 05:59
6

Had the same with django=4.1.4, channels=4.0.0

My solution:

  1. install channels with daphne (i did not remove or did anything to previously installed channels; operating in the same venv)

python -m pip install -U channels["daphne"]

  1. put daphne in INSTALLED APPS, do not put channels there:

INSTALLED_APPS = ( "daphne", "django.contrib.auth",...

  1. in settings.py add ASGI_APPLICATION:

ASGI_APPLICATION = "myproject.asgi.application"

worsekey
  • 61
  • 1
  • 1
6

At the first:

pip install daphne
pip install channels

And then update setting.py:

INSTALLED_APPS = [
    'daphne',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

Just this.

reza_khalafi
  • 6,230
  • 7
  • 56
  • 82
2

From channels 4.0.0 Release Notes documentation:

In order to allow users of other ASGI servers to use Channels without the overhead of Daphne and Twisted, the Daphne application server is now an optional dependency, installable either directly or with the daphne extra, as per the pip example above. Where Daphne is used daphne>=4.0.0 is required. The channels[daphne] extra assures this.

The runserver command is moved to the daphne package.

In order to use the runserver command, add daphne to your INSTALLED_APPS, before django.contrib.staticfiles:

INSTALLED_APPS = [ "daphne", ... ]

As you can see the runserver command is moved to the daphne package. So you have to install and include it as mentioned here before

0

Use version of python that support by channels, you will found it at pypi channels page

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 31 '22 at 10:10
0

I had the same problem, and found that there was a new release of Channels. Since the project's Pipfile did not specify a version, it was automatically upgraded.

Maybe you had the same issue, your question was asked 2 days after Channels v4.0 release.

Downgrading to v3.0.5 again solved the problem until I can properly upgrade.

lfagundes
  • 2,978
  • 5
  • 24
  • 25