文件加载出现 _pickle.UnpicklingError: could not find MARK

今天在调式项目代码时,出现加载文件的的错误
_pickle.UnpicklingError: could not find MARK
在这里插入图片描述

在使用pickle反序列化的时候,要预先导入二进制数据中存在的自定义类数据的类

pickle反序列化的原理,反序列化应该是根据一个模板将二进制数据还原的过程,所以应该导入序列化时自定义类型

解决方法:

错误 _pickle.UnpicklingError: could not find MARK```引发是因为文件的偏移量不在开头。解决方法是拨打f.seek(0)`在加载 pickle 之前。
在这里插入图片描述
希望这能够对你有用!

猜你喜欢

转载自blog.csdn.net/qq_44936246/article/details/121594103