版本

python3.11版本,aioredis 2.0.1版本,redis 7.x版本

redis.conf配置文件

daemonize yes
bind 0.0.0.0
port 6379
protected-mode no

代码

from fastapi import FastAPI
import aioredis app = FastAPI() @app.on_event('startup')
async def startup_event():
# 线程池
app.state.redis_client = aioredis.from_url('redis://xxx.xxx.xxx.xx/0',encoding="utf-8", decode_responses=True) @app.on_event('shutdown')
async def shutdown_event():
await app.state.redis_client.close() @app.get('/index')
async def index():
key = 'liuwei'
# 设置缓存
await app.state.redis_client.set(key, '123456') # 读取
result = await app.state.redis_client.get(key)
print(result)
return {'msg': 'ok'} if __name__ == '__main__':
import uvicorn
uvicorn.run(app='main:app', host='0.0.0.0', port=8001, reload=True)

报错

File "f:\all_django_project\pyscript_demo\main.py", line 2, in <module>
import aioredis
File "F:\all_django_project\pyscript_demo\fast_api_env\Lib\site-packages\aioredis\__init__.py", line 1, in <module>
from aioredis.client import Redis, StrictRedis
File "F:\all_django_project\pyscript_demo\fast_api_env\Lib\site-packages\aioredis\client.py", line 32, in <module>
from aioredis.connection import (
File "F:\all_django_project\pyscript_demo\fast_api_env\Lib\site-packages\aioredis\connection.py", line 33, in <module>
from .exceptions import (
File "F:\all_django_project\pyscript_demo\fast_api_env\Lib\site-packages\aioredis\exceptions.py", line 14, in <module>
class TimeoutError(asyncio.TimeoutError, builtins.TimeoutError, RedisError):
TypeError: duplicate base class TimeoutError

定位分析

  File "F:\all_django_project\pyscript_demo\fast_api_env\Lib\site-packages\aioredis\exceptions.py", line 14, in <module>
class TimeoutError(asyncio.TimeoutError, builtins.TimeoutError, RedisError):
TypeError: duplicate base class TimeoutError 启动连接时会报一个TypeError: duplicate base class TimeoutError的错误
问了Copilot,说是兼容性问题,在 Python3.11 中,asyncio.TimeoutError 被移动到了 asyncio.exceptions 模块中,而 aioredis 库没有及时更新以适应这个变化。
所以我们找到aioredis目录下的exceptions.py文件,定位到14行代码
class TimeoutError(asyncio.TimeoutError, builtins.TimeoutError, RedisError):
pass 所以我们修改为如下代码,即可运行
class TimeoutError(asyncio.exceptions.TimeoutError, RedisError):
pass

异步aioredis连接时报错TypeError: duplicate base class TimeoutError问题的更多相关文章

  1. Ajax上传文件/照片时报错TypeError :Illegal invocation

    问题 Ajax上传文件/照片时报错TypeError :Illegal invocation 解决 网上搜索问题,错误原因可能有以下几个,依次检查: 请求类型有误,如post请求,但在后台设置的是ge ...

  2. 解决Win7、Win10登录远程桌面连接时报错、提示“要求的函数不受支持”问题

    解决Win7.Win10登录远程桌面连接时报错.提示"要求的函数不受支持"问题远程登录主机时地址,用户名,密码均正确,但是提示错误"要求的函数不受支持": 解决 ...

  3. 执行python manage.py makemigrations时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'

    在执行python manage.py makemigrations时报错: TypeError: __init__() missing 1 required positional argument: ...

  4. Django :执行 python manage.py makemigrations 时报错 TypeError: __init__() missing 1 required positional argument: 'on_delete'

    原因 执行命令 python manage.py makemigrations 报错 TypeError: __init__() missing 1 required positional argum ...

  5. 使用JDBC获取Oracle连接时报错

    The Network Adapter could not establish the connection       网络适配器不能创建连接 作为初学者的来说,这个问题让我找了好多次,每次重新开启 ...

  6. mysql数据库打开连接时报错:1251

    考试之前由于一直在做团队项目导致疏忽了数据库 等到今天来连接做考试的时候发现报错:1251 网上的解释以及解决方法: 今天下了个 MySQL8.0,发现Navicat连接不上,总是报错1251: 原因 ...

  7. statsmodels.tsa.arima_model预测时报错TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'

    在 python 中用 statsmodels创建 ARIMA 模型进行预测时间序列: import pandas as pd import statsmodels.api as sm df = pd ...

  8. MySQL使用Navicat远程连接时报错1251

    1.报错信息 client does not support authentication protocol requested by server:consider upgrading MySQL ...

  9. moviepy执行TextClip.search方法时报错TypeError: a bytes-like object is required, not str

    ☞ ░ 前往老猿Python博文目录 ░ 执行TextClip.search方法时,报错: >>> from moviepy.editor import * >>> ...

  10. Django关联数据库时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'

    sgrade = models.ForeignKey("Grades",) 执行python manage.py makemigrations后出现TypeError: __ini ...

随机推荐

  1. [转帖]jmap执行失败了,怎么获取heapdump?

    https://www.jianshu.com/p/f4bfd169b4ca   在之前的OOM问题复盘中,我们添加了jmap脚本来自动dump内存现场,方便排查OOM问题. 但当我反复模拟OOM场景 ...

  2. [转帖]ELKStack入门篇(二)之Nginx、Tomcat、Java日志收集以及TCP收集日志使用

    https://www.cnblogs.com/linuxk/p/9273160.html 1.收集Nginx的json格式日志 1.1.Nginx安装   1.2.配置logstash [root@ ...

  3. [转帖]细说Redis监控和告警

    https://blog.csdn.net/sD7O95O/article/details/78096956 对于任何应用服务和组件,都需要一套完善可靠谱监控方案.尤其redis这类敏感的纯内存.高并 ...

  4. [转帖]一个故事看懂CPU的TLB

    https://www.cnblogs.com/xuanyuan/p/15347054.html Hi,我是CPU一号车间的阿Q,还记得我吗,真是好久不见了- 我所在的CPU是一个八核CPU,就有八个 ...

  5. Oracle DBCA 静默删除以及建库的脚本

    No.1 背景 公司最近有一个测试环境需要重新备份恢复 但是里面有6个数据库实例 400多G的数据文件. 一般情况下 需要drop user xxx cascade ; 然后执行 drop table ...

  6. node借助jsonwebtoken生成token以及验证token是否过期

    生成token使用 jsonwebtoken 插件 我当时使用的版本"jsonwebtoken": "^9.0.0", cnpm i jsonwebtoken ...

  7. CANVAS ----- 鼠标移动画圆

    1.增加鼠标移动事件 $('#canvas').mousemove(function (e) { draw(event); }); 2.获取鼠标在canvas上的坐标 function getCanv ...

  8. Pytest 源码解读 [1] - [pluggy] 核心设计理念浅读

    背景: Pytest 是一个功能强大的 Python 测试框架,它使用了一个名为 "pluggy" 的插件系统来扩展其功能.在 Pytest 的源码中,pluggy 模块负责实现插 ...

  9. 基于 hugging face 预训练模型的实体识别智能标注方案:生成doccano要求json格式

    强烈推荐:数据标注平台doccano----简介.安装.使用.踩坑记录_汀.的博客-CSDN博客_doccano huggingface官网 参考:数据标注平台doccano----简介.安装.使用. ...

  10. 14代i5-14600K现身:多核性能提升多达11%

    14代酷睿桌面端还未发售,就陆续在跑分平台上露出. 平台规格为Z790主板.32GB DDR5-5200内存,酷睿i5-14600K的单核成绩为2819,多核成绩为16666,对比酷睿i5-13600 ...