Django Channels Error - Cannot import BACKEND 'asgi_redis.RedisChannelLayer'

牧云@^-^@ 提交于 2019-12-01 00:06:20

问题


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.


回答1:


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



回答2:


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

pip install channels_redis



回答3:


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.




回答4:


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

NOT asgi_redis.

pip install channel_redis



回答5:


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


来源:https://stackoverflow.com/questions/37342571/django-channels-error-cannot-import-backend-asgi-redis-redischannellayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!