1. I am currently trying to read skyblock inventory and I do realise that the data is base64 encoded with gzip compression. My problem is that when I do decode and decompress I still get bytes instead of plain text. I have no experience of the nbt format.

    data_base64 = 'H4sIAAAAAAAAAN2bW3PjyHXHuV47Ozv..........0EAAA\u003d\u003d'
    nbt_data = gzip.decompress(base64.b64decode(data_base64))
    nbt = nbt.NBTFile(nbt_data)

    b'\n\x00\x00\t\x00\x01i\n\x00\x00\x00$\x02\x00\x02id\x01\x1f\x01\x00\x05Count\x01\n\x00\x03tag\t\x00\x04ench\x00\x00\x00\x00\x00\x03\x00\tHideFlags\x00\x00\x00\xfe\n\x00\x07display\t\x00\x04Lore\x08\x00\x00\x00\r\x00 \xc2\xa77Strength: \xc2\xa7c+7 \xc2\xa7c(Godly +7)\x00%\xc2\xa77Crit Chance:

    At the last command I get the following error:
    File "C:\Users\...\decode.PY", line 10, in <module>
    nbt = nbt.NBTFile(nbt_data)
    File "./NBT-1.5.0/nbt\nbt.py", line 613, in __init__
    self.file = GzipFile(filename, 'rb')
    File "C:\Users\...\Python\Python37\lib\gzip.py", line 163, in __init__
    fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 61: invalid start byte
  2. Hi, this is an issue with you data_base64 string. You have to convert '\u003d' to '=' at the end and it will works perfectly :)
  3. I've tried that both ways with "==" and in escape characters format and they still do not work.
  4. Try to create a fileobj for your nbt_data. I personally do not use gzip.decompress but io.BytesIO from io:
    import nbt
    import io
    import base64
    def decode_inventory_data(raw):
       data = nbt.nbt.NBTFile(fileobj = io.BytesIO(base64.b64decode(raw)))
  5. Well it seems like the decoding worked but when calling .pretty_tree() it crashes
    Traceback (most recent call last):
    File "C:\Users\Zaopoas\Desktop\DP\pTHON\decode.PY", line 16, in <module>
    File "C:\Users\Zaopoas\Desktop\DP\pTHON\decode.PY", line 10, in decode_inventory_data
    File "C:\Users\Zaopoas\AppData\Local\Programs\Python\Python37\lib\encodings\cp1253.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
    UnicodeEncodeError: 'charmap' codec can't encode characters in position 912-914: character maps to <undefined>
    [Finished in 0.1s]

    {TAG_List('i'): [36 TAG_Compound(s)]}
    [Finished in 0.1s]

Share This Page