[Answer]-Error Trying to Import JSON to Django Database – TypeError: string indices must be integers


The problem is here:

for item in result['itemdata']

itemdata is a dict (of dicts). In Python, iterating through a dict yields the keys: so item there is “blink”, “blades_of_attack”, and so on, hence the error.

You don’t seem to want the keys at all, so you should iterate through result['itemdata'].values().

(Note there is an indentation error in update_item: the line db_item = Item() should be indented within the except, otherwise a new item will always be created.)


def handle(self, *args, **options):
      self.stdout.write('Fetching item list..')
      result = SteamWrapper.get_item_list

The line result = SteamWrapper.get_item_list makes result point at a method of SteamWrapper named get_item_list. Perhaps you’ve meant to call it by typing SteamWrapper.get_item_list()?

Leave a comment