You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用SQLAlchemy读取Python2旧版本生成的Pickle文件时遭遇KeyError: '_index'错误求助

SQLAlchemy读取Python2旧版本生成的Pickle文件时遭遇KeyError: '_index'错误求助

我有一个用Python 2和旧版SQLAlchemy(版本1.0.14)生成的Pickle文件,它是一个MySQL数据库模板。

为了读取这个文件,我写了如下脚本:

import pickle
import os
from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import create_session
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.engine.reflection import Inspector

template_path = os.path.join(os.getcwd(), 'mysqldb_file')

with open(template_path, "rb") as file:
    src_tables = pickle.load(file)

但运行这个脚本时,我遇到了以下错误:

src_tables = pickle.load(file)
File "C:\Users\MEGAPC\anaconda3\lib\site-packages\sqlalchemy\sql\base.py", line 1328, in setstate
object.setattr(self, "_index", state["_index"])
KeyError: '_index'

我没有任何数据库和SQLAlchemy相关的使用经验,实在不知道该怎么解决这个问题,有没有大佬能帮我一下?非常感谢!

备注:内容来源于stack exchange,提问作者RACHID MOUSTABCHIR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 11:53:04