twoolie / NBT

Python Parser/Writer for the NBT file format, and it's container the RegionFile.
MIT License
361 stars 74 forks source link

Proble: TypeError: string indices must be integers #143

Closed CocoaCrispies closed 3 years ago

CocoaCrispies commented 3 years ago

When parsing NBT data decoded from Base64 string, and parsing it, I'm getting the typerror above. Here is my code: https://pastebin.com/3Ak0m6YL

Here are my logs: https://pastebin.com/mDV5fnf9

Thanks in advance!

macfreek commented 3 years ago

Hi CocoaCrispies,

I'm afraid your bug report does not give me much pointers to help you.

  1. You are submitting this bug report for a package called 'nbt'. However, it's unclear if you use this package at all. The only reference to a package seems to be to python3.7/site-packages/discord, not to python3.7/site-packages/nbt.
  2. According to the log, the error in a line piece = nbt['i'].tags[0]['tag']['display']['Name']. However that line does not occur in your code (which defines a function inventory_data, but does not contain any reference to NBT data at all).

That said, TypeError: string indices must be integers usually means that you are trying to do something like this:

>>> nbt = "hello world"
>>> nbt[6]
'w'
>>> nbt['i']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string indices must be integers

So, I suspect that your data structure is different from what you suspect. You seem to suspect a dict, but the data is a string. However, with the limited information you provided, I can't determine if nbt, nbt['i'].tags[0], nbt['i'].tags[0]['tag'] or nbt['i'].tags[0]['tag']['display'] is a string instead of a dict.