为什么“bson”库在 Jupyter Notebook 中不起作用

问题描述 投票:0回答:2

我正在尝试读取 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 中运行此代码时,我没有收到任何错误。

python file jupyter-notebook google-colaboratory bson
2个回答
0
投票

您尝试过使用

loads
方法吗

with open("D:/rl env/chat_log.bson",'r') as f: 
    datas = bson.loads(f.read())

0
投票

decode_all()
是 pymongo API 的一部分,而不是您可能已安装的 bson 包。看这里:https://github.com/py-bson/bson/issues/41https://github.com/py-bson/bson/issues/102

© www.soinside.com 2019 - 2024. All rights reserved.