Django Channels error - unable to import BACKEND 'asgi_redis.RedisChannelLayer'

I installed Django-Channels, but when I start the daphne server, I get the following error:

File "/usr/local/lib/python2.7/dist-packages/channels/asgi.py", line 36, in make_backend "Cannot import BACKEND %r specified for %s" % (self.configs[name]['BACKEND'], name) channels.asgi.InvalidChannelLayerError: Cannot import BACKEND 'asgi_redis.RedisChannelLayer' specified for default 

My settings.py options:

 CHANNEL_LAYERS = { "default": { "BACKEND": "asgi_redis.RedisChannelLayer", "CONFIG": { "hosts": [os.environ.get('REDIS_URL', 'redis://XXXX:6379')], }, "ROUTING": "MyProject.routing.channel_routing", }, } 

Need help resolving this error.

+6
source share
6 answers

Just need to set 'asgi_redis'. I assumed that it would be installed by default when installing Django-Channels, but that is not the case. "asgiref" is set by default, not "asgi_redis". Therefore, to solve this problem, you can simply run:

 > sudo pip install asgi_redis 
+10
source

With asgiref-2.3.2 and possibly more, you need to set channel_redis.

NOT asgi_redis.

 pip install channel_redis 
+3
source

Regarding Utkarsh's answer, it has been renamed to:

 pip install channels_redis 
+1
source

I get a slightly different error:

 "channels.asgi.InvalidChannelLayerError: Cannot import BACKEND 'asgiref.inmemory.ChannelLayer' specified for default" 

Jayati Deshmukh answer helped me. This error disappeared after downgrading asgiref to 1.0.0.

0
source

I also ran into the same problem when working with django-channel, following the documentation examples Official Django channel documentation, you just need to install-redis channels as

pip install channel-redis

to solve this problem.

0
source

In my case, version of asgiref 2.3.2 was incompatible. I downgraded it as follows, and then my code worked.

 pip install asgiref==1.0.0 
-1
source

All Articles