my code here:
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)
I try to convert BSON to JSON. But I get error:
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
I hope anyone had already encountered such error, what did you do?
.bsonfiles where the decode is failing.