我正在尝试读取 bson 文件,这是我的代码:
import bson
with open("D:/rl env/chat_log.bson",'rb') as f:
datas = bson.decode_all(f.read())
注意 “D:/rl env/chat_log.bson” 是我的文件路径。 我收到以下错误:
AttributeError:模块“bson”没有属性“decode_all”
我必须提到,当我在 google colab 中运行此代码时,我没有收到任何错误。
您尝试过使用
loads
方法吗
with open("D:/rl env/chat_log.bson",'r') as f:
datas = bson.loads(f.read())
decode_all()
是 pymongo API 的一部分,而不是您可能已安装的 bson 包。看这里:https://github.com/py-bson/bson/issues/41和https://github.com/py-bson/bson/issues/102