Home > Blockchain >  Convert bytes in string using python
Convert bytes in string using python

Time:10-31

I have bson file, and i dont know what have inside of the document. I see the data type, and conclude the type of data is bytes. So, for undertsand the content the file, i need to save in readable formart. So, the firt step was convert my bytes in a string.. But, i return the following message:

TypeError: descriptor 'decode' for 'bytes' objects doesn't apply to a 'str' object

To resolve this, i used the function: str1 = bytes_content.decode('latin-1') and doesn't return anything. After, i using the: str2 = bytes_content.decode('cp437').

And after this, i did a print, and doesnt'return anything :( I stay convert bytes in string in bson file.. For after this, can read this document, because this is bson file

My code

CodePudding user response:

You are saving the type object into your bytes_content variable.

bytes_content = read_content["data"]
  • Related