0
votes

I get the error "TypeError: string indices must be integers" in the following code:

if body['category'] == 'Character':
        return sanic.response.json([], status=200)

Body:

{
        "lockerItem": "sandbox_loadout",
        "category": "Character",
        "itemToSlot": "AthenaCharacter:CID_279_Athena_Commando_M_TacticalSanta",
        "slotIndex": 0,
        "variantUpdates": [
                {
                        "channel": "Parts",
                        "active": "Stage0",
                        "owned": []
                }
        ],
        "optLockerUseCountOverride": -1
}

Full Error:

    if body['category'] == 'Character':
TypeError: string indices must be integers
1
Where do you get body from? It looks like it is still a json string. You need to get it converted to a dict. - quamrana

1 Answers

1
votes

Verify your body variable type, the reason why you're getting TypeError: string indices must be integers is because the body is of a string type and only integers indices can be used on a string.

You need to either convert your variable to a dict type where string indices can be used or ensure the variable you received is of a dict type