Django Channels Error - Cannot import BACKEND 'asgi_redis.RedisChannelLayer'
Asked Answered
K

9

16

I have installed Django-Channels but while running the daphne-server I am getting this error given below:

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 is:

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

Need help in resolving this error.

Kirovabad answered 20/5, 2016 at 9:8 Comment(0)
K
13

Just needed to install 'asgi_redis'. I was assuming that it would have gotten installed by default while installing Django-Channels, but it doesn't. 'asgiref' gets installed by default and not 'asgi_redis'. So to solve this issue, one can just run:

> sudo pip install asgi_redis
Kirovabad answered 20/5, 2016 at 12:5 Comment(4)
I found this to be also true for "Cannot import BACKEND 'channels_redis.core.RedisChannelLayer'": pip install channels_redis. Thank you.Northernmost
With asgiref-2.3.2 i need to install channel_redis. NOT asgi_redisPalaeozoology
@jlSta, great, this solved one of the issues with new channels 2.x, wish it was written in the docs (and, it's channels_redis)X
I add this as a solution, soPalaeozoology
V
31

In regard to Utkarsh's reply itt's been renamed to:

pip install channels-redis
Valdivia answered 30/11, 2018 at 13:57 Comment(2)
Thanks for pointing it out @drulang. For anyone trying to install Django Channels 2, the documentation describes the changes that have taken place here - channels.readthedocs.io/en/latest/…Kirovabad
I think it should be pip install channels_redis. Worked for me at least...Scrotum
K
13

Just needed to install 'asgi_redis'. I was assuming that it would have gotten installed by default while installing Django-Channels, but it doesn't. 'asgiref' gets installed by default and not 'asgi_redis'. So to solve this issue, one can just run:

> sudo pip install asgi_redis
Kirovabad answered 20/5, 2016 at 12:5 Comment(4)
I found this to be also true for "Cannot import BACKEND 'channels_redis.core.RedisChannelLayer'": pip install channels_redis. Thank you.Northernmost
With asgiref-2.3.2 i need to install channel_redis. NOT asgi_redisPalaeozoology
@jlSta, great, this solved one of the issues with new channels 2.x, wish it was written in the docs (and, it's channels_redis)X
I add this as a solution, soPalaeozoology
C
7

I also faced same problem while working with django-channels, by following the documentation examples https://channels.readthedocs.io/en/latest/tutorial/index.html you just need to install channels-redis as

pip install channels-redis

to resolve this issue.

Credential answered 5/4, 2019 at 6:54 Comment(0)
P
6

With asgiref-2.3.2 and maybe more, you need to install channel_redis.

NOT asgi_redis.

pip install channel_redis
Palaeozoology answered 30/10, 2018 at 9:53 Comment(2)
Yes! Use this for channels. I am using channels 2.1.5. e.g. pip install channels==2.1.5 (This version also installs asgiref==2.3.2)Bridgeboard
I think it should be channels_redisClassieclassification
M
4

Faced the similar issue. Solved it by installing channels_redis:

pip install channels_redis

Also using channel redis in setting too:

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            'hosts': [('localhost', 6379)],
        },
    },
    'ROUTING': 'ws.routing.application',
}
Mernamero answered 7/5, 2020 at 2:35 Comment(1)
thanks, pip install channel_redis solved my problem.Scrotum
W
1

That did the thing for me.

daphne = "~=3.0.2"
channels = "~=3.0.4"
channels-redis = "~=3.3.1"
async-timeout = "~=3.0.1"
Windhoek answered 9/2, 2022 at 16:7 Comment(0)
F
1

In my case channels_redis version 4.2.0 was not compatible. I downgraded it as follows and my code worked:

pip install channels_redis==3.3.1
Florencio answered 16/2 at 10:16 Comment(0)
S
0

In my case asgiref version 2.3.2 was not compatible. I downgraded it as follows and then my code worked.

pip install asgiref==1.0.0
Smiley answered 22/10, 2018 at 3:39 Comment(1)
See comment from jlSta above, e.g. pip install channel_redisBridgeboard
B
0

I know this is an old post, however, I got the same problem and I got the solution from this link:

https://github.com/django/channels_redis/issues/113#issuecomment-405071710

based on Andrewgodwin he says:

"asgi-redis is an outdated package (the previous version of channels_redis). You can uninstall it to solve this error."

and that worked for me

Bobbitt answered 2/11, 2022 at 23:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.