任何人都可以使用Django渠道帮助我解决此错误

时间:2020-05-17 11:59:41

标签: python django django-channels

我正在使用渠道开发聊天应用程序。这是链接to the documentation

当我尝试与Redis通信时。它给出了这个错误。安装了该库。逐步实施文档并得到此错误。

>>> import channels.layers
>>> channel_layer = channels.layers.get_channel_layer()
>>> from asgiref.sync import async_to_sync
>>> async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'})
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\asgiref\sync.py", line 120, in __call__
    return call_result.result()
  File "c:\users\hp\appdata\local\programs\python\python36\lib\concurrent\futures\_base.py", 
line 425, in result
    return self.__get_result()
  File "c:\users\hp\appdata\local\programs\python\python36\lib\concurrent\futures\_base.py", 
line 384, in __get_result
    raise self._exception
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\asgiref\sync.py", line 180, in main_wrap
    result = await self.awaitable(*args, **kwargs)
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\channels_redis\core.py", line 299, 
in send
    async with self.connection(index) as connection:
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\channels_redis\core.py", line 835, 
in __aenter__
    self.conn = await self.pool.pop()
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\channels_redis\core.py", line 73, in pop
    conns.append(await aioredis.create_redis(**self.host, loop=loop))
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\aioredis\commands\__init__.py", line 175, in create_redis
    loop=loop)
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\aioredis\connection.py", line 113, 
in create_connection
    timeout)
  File "c:\users\hp\appdata\local\programs\python\python36\lib\asyncio\tasks.py", line 339, in wait_for
    return (yield from fut)
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\aioredis\stream.py", line 24, in open_connection
    lambda: protocol, host, port, **kwds)
  File "c:\users\hp\appdata\local\programs\python\python36\lib\asyncio\base_events.py", line 
778, in create_connection
    raise exceptions[0]
  File "c:\users\hp\appdata\local\programs\python\python36\lib\asyncio\base_events.py", line 
765, in create_connection
    yield from self.sock_connect(sock, address)
  File "c:\users\hp\appdata\local\programs\python\python36\lib\asyncio\selector_events.py", line 450, in sock_connect
    return (yield from fut)
  File "c:\users\hp\appdata\local\programs\python\python36\lib\asyncio\selector_events.py", line 480, in _sock_connect_cb
    raise OSError(err, 'Connect call failed %s' % (address,))
ConnectionRefusedError: [Errno 10061] Connect call failed ('127.0.0.1', 6379)
>>> async_to_sync(channel_layer.receive)('test_channel')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\asgiref\sync.py", line 120, in __call__
    return call_result.result()
  File "c:\users\hp\appdata\local\programs\python\python36\lib\concurrent\futures\_base.py", 
line 425, in result
    return self.__get_result()
  File "c:\users\hp\appdata\local\programs\python\python36\lib\concurrent\futures\_base.py", 
line 384, in __get_result
    raise self._exception
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\asgiref\sync.py", line 180, in main_wrap
    result = await self.awaitable(*args, **kwargs)
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\channels_redis\core.py", line 467, 
in receive
    return (await self.receive_single(channel))[1]
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\channels_redis\core.py", line 490, 
in receive_single
    index, channel_key, timeout=self.brpop_timeout
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\channels_redis\core.py", line 330, 
in _brpop_with_clean
    async with self.connection(index) as connection:
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\channels_redis\core.py", line 835, 
in __aenter__
    self.conn = await self.pool.pop()
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\channels_redis\core.py", line 73, in pop
    conns.append(await aioredis.create_redis(**self.host, loop=loop))
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\aioredis\commands\__init__.py", line 175, in create_redis
    loop=loop)
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\aioredis\connection.py", line 113, 
in create_connection
    timeout)
  File "c:\users\hp\appdata\local\programs\python\python36\lib\asyncio\tasks.py", line 339, in wait_for
    return (yield from fut)
  File "C:\Users\hp\Desktop\django\venv\lib\site-packages\aioredis\stream.py", line 24, in open_connection
    lambda: protocol, host, port, **kwds)
  File "c:\users\hp\appdata\local\programs\python\python36\lib\asyncio\base_events.py", line 
778, in create_connection
    raise exceptions[0]
  File "c:\users\hp\appdata\local\programs\python\python36\lib\asyncio\base_events.py", line 
765, in create_connection
    yield from self.sock_connect(sock, address)
  File "c:\users\hp\appdata\local\programs\python\python36\lib\asyncio\selector_events.py", line 450, in sock_connect
    return (yield from fut)
  File "c:\users\hp\appdata\local\programs\python\python36\lib\asyncio\selector_events.py", line 480, in _sock_connect_cb
    raise OSError(err, 'Connect call failed %s' % (address,))
ConnectionRefusedError: [Errno 10061] Connect call failed ('127.0.0.1', 6379)

0 个答案:

没有答案