我正在尝试复制Mikhail Andreev与Django频道的聊天,请在此处发布:https://gearheart.io/blog/creating-a-chat-with-django-channels/
当我运行服务器:$ python3 ./manage.py runserver时,redis服务器没有启动。下面是完整的信息:
Performing system checks...
System check identified no issues (0 silenced).
April 27, 2017 - 20:59:01
Django version 1.10.3, using settings 'multichat.settings'
Starting Channels development server at http://127.0.0.1:8000/
Channel layer default (asgi_redis.core.RedisChannelLayer)
Quit the server with CONTROL-C.
2017-04-27 20:59:01,278 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
2017-04-27 20:59:01,279 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
2017-04-27 20:59:01,282 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
2017-04-27 20:59:01,282 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.receive
2017-04-27 20:59:01,283 - INFO - server - HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2017-04-27 20:59:01,283 - INFO - server - Using busy-loop synchronous mode on channel layer
2017-04-27 20:59:01,284 - INFO - server - Listening on endpoint tcp:port=8000:interface=127.0.0.1
2017-04-27 20:59:01,294 - ERROR - server - Error trying to receive messages: Error 61 connecting to localhost:6379. Connection refused.
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 439, in connect
sock = self._connect()
File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 494, in _connect
raise err
File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 482, in _connect
sock.connect(socket_address)
ConnectionRefusedError: [Errno 61] Connection refused 我可以通过从不同的终端运行redis服务器来解决这个问题,但是这是Django频道在设置中应该做的事情:
redis_host = os.environ.get('REDIS_HOST', 'localhost')
# Channel layer definitions
# http://channels.readthedocs.org/en/latest/deploying.html#setting-up-
a-channel-backend
CHANNEL_LAYERS = {
"default": {
# This example app uses the Redis channel layer implementation asgi_redis
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [(redis_host, 6379)],
},
"ROUTING": "multichat.routing.channel_routing", # We will create it in a moment
},
}感谢任何帮助和建议。
非常感谢!
发布于 2017-04-28 09:54:59
请参阅https://github.com/django/daphne#http2-support
您应该安装扭曲的pip install -U Twisted[tls,http2]
发布于 2017-08-20 14:10:38
Django频道将不会自动启动Redis。Redis是一个单独的服务,它应该已经在您的机器上或其他地方运行。Channels依赖Redis作为消息代理的后端。
来自Redis
BSD是一个开源(
许可)的内存数据结构存储,用作数据库、缓存和消息代理。
您需要遵循Redis的Installation说明,并使用以下命令启动:
$ /path/to/redis-server你的Django应用程序也应该是正确的configured to use Redis。您还需要在Python virtual environment中安装asgi_redis包(如果使用的话)。
正如您从粘贴的错误消息中看到的,Django通道无法连接到localhost:6379,因为Redis可能没有运行。
2017-04-27 20:59:01,294 -错误-服务器-尝试接收消息时出错:连接到本地主机时出现错误61 :6379。连接被拒绝。线程线程-1异常:回溯(最近一次调用):文件"/usr/local/lib/python3.6/site-packages/redis/connection.py",行439,在connect sock = self._connect()文件"/usr/local/lib/python3.6/site-packages/redis/connection.py",行494,在_connect raise err文件"/usr/local/lib/python3.6/site-packages/redis/connection.py",行482,in _connect sock.connect(socket_address) ConnectionRefusedError:错误号61连接被拒绝
更新(2019-02-26)的
asgi_redis包是针对通道1.x的,而对于通道2.x,则需要。
发布于 2019-06-18 17:51:18
我想你已经在virtualenv中安装了redis channel。我也遇到了同样的问题,然后我也在本地安装了redis,然后它运行得很好。您将看到服务(本地)在那里找到Redis服务器。
对于redis安装,您可以使用ubuntu的链接:https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-18-04
https://stackoverflow.com/questions/43668401
复制相似问题