Channels_redis 导致错误 AttributeError: 'Redis' object has no attribute 'bzpopmin'

问题描述

我的 Django 应用程序遇到以下错误消息:

Exception inside application: 'Redis' object has no attribute 'bzpopmin'
Traceback (most recent call last):
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels/staticfiles.py",line 44,in __call__
    return await self.application(scope,receive,send)
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels/routing.py",line 71,in __call__
    return await application(scope,send)
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels/sessions.py",line 47,in __call__
    return await self.inner(dict(scope,cookies=cookies),line 254,in __call__
    return await self.inner(wrapper.scope,wrapper.send)
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels/auth.py",line 181,in __call__
    return await super().__call__(scope,send)
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels/middleware.py",line 26,in __call__
    return await self.inner(scope,line 160,in __call__
    send,File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels/consumer.py",line 94,in app
    return await consumer(scope,send)
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels/consumer.py",line 59,in __call__
    [receive,self.channel_receive],self.dispatch
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels/utils.py",line 58,in await_many_dispatch
    await task
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels/utils.py",line 50,in await_many_dispatch
    result = task.result()
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels_redis/core.py",line 469,in receive
    real_channel
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels_redis/core.py",line 524,in receive_single
    index,channel_key,timeout=self.brpop_timeout
  File "/home/jack/.conda/envs/GuessWhich/lib/python3.7/site-packages/channels_redis/core.py",line 361,in _brpop_with_clean
    result = await connection.bzpopmin(channel,timeout=timeout)
AttributeError: 'Redis' object has no attribute 'bzpopmin'

这似乎是在创建 WebSocket 连接后,在抛出错误后断开 WebSocket 连接。

起初我查看了由于使用低于 5.0 的 Redis 版本而导致的其他类似问题,但在输入命令 redis-cli INFO | grep version 后,我可以看到我的机器上安装的 Redis 版本是 6.0.9这也适用于从 Python 内部调用类似函数的情况。

在这一点上,我认为问题可能是由于运行了一个独立版本的 Redis(可能来自其他一些依赖项?)但我在我的机器上找不到这方面的证据,或者是由于将通道的版本从 1 升级到3 并留下一些遗留代码。我没有成功找到与我面临的问题类似的问题,也不确定这些假设中的任何一个是否正确。

解决方法

为了回答我遇到的这个问题,我不能 100% 确定是什么损坏了,但我使用的是 conda 环境,其中包含通过 conda 和 pip 安装的混合包(pip 似乎也已损坏)。移除并重新创建环境,并使用pip安装所有包后,此问题已解决。

,

我遇到了同样的错误并通过更新 aioredis 修复了它。