import os
import bson
from bson.codec_options import CodecOptions
bson_codec_options = CodecOptions(
datetime_conversion='DATETIME_AUTO',
tz_aware=True,
unicode_decode_error_handler='ignore'
)
if __name__ == '__main__':
current_dir = os.getcwd()
bson_files = []
for file in os.listdir(current_dir):
current_item = os.path.join(current_dir, file)
if os.path.isfile(current_item) and file.endswith(".bson"):
bson_files.append(file)
for file in bson_files:
with open(os.path.join(current_dir, file), 'rb') as fcache:
data = bson.decode(fcache.read(), codec_options=bson_codec_options)
print(data)
Я пытаюсь преобразовать BSON в JSON. Но я получаю ошибку:
File "C:\PyProjects\zulip\.venv\Lib\site-packages\bson\__init__.py", line 1094, in decode
return cast("Union[dict[str, Any], _DocumentType]", _bson_to_dict(data, opts))
^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'str' object cannot be interpreted as an integer
Надеюсь, кто-нибудь уже сталкивался с такой ошибкой, что вы делали?
for file in os.listdir(current_dir): current_item = os.path.join(current_dir, file) if os.path.isfile(current_item) and file.endswith(".bson"): bson_files.append(file)
for file in bson_files:
with open(os.path.join(current_dir, file), 'rb') as fcache: data = bson.decode(fcache.read(), codec_options=bson_codec_options) print(data) [/code] Я пытаюсь преобразовать BSON в JSON. Но я получаю ошибку: [code]File "C:\PyProjects\zulip\.venv\Lib\site-packages\bson\__init__.py", line 1094, in decode return cast("Union[dict[str, Any], _DocumentType]", _bson_to_dict(data, opts)) ^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'str' object cannot be interpreted as an integer [/code] Надеюсь, кто-нибудь уже сталкивался с такой ошибкой, что вы делали?
+++
Редактировать: долгое время после помесщения вопроса онлайн я заметил, что это дополнение к базе данных Mongodb 2.0.5 с Pimongo 2.2, которое говорит, что вы должны установить BSON, прежде чем установить Pymongo. Я спрашиваю здесь не об этом уже...