Ошибка: TypeError: string indices must be integers (только в телеграм бот)
Делаю телеграмм бота, в одном из хэндлеров получаю JSON:
pretty_json = json.dumps(tasksget, ensure_ascii=False, default=str)
[
{
"timeEstimate":"1800",
"id":"573",
"group":[
]
},
{
"timeEstimate":"1800",
"id":"575",
"group":[
]
},
{
"timeEstimate":"7200",
"id":"577",
"group":[
]
}
]
После, с помощью цикла я суммирую все значения "timeEstimate" (объектов в JSON может быть разное количество), вот цикл:
for item in pretty_json:
duration += int(item['timeEstimate'])
count += 1
Если код выполнять отдельно от бота, то ошибок нет, но если в боте тогда постоянно ошибка:
Traceback (most recent call last):
File "/home/local/.local/lib/python3.10/site-packages/aiogram/dispatcher/dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "/home/local/.local/lib/python3.10/site-packages/aiogram/dispatcher/dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "/home/local/.local/lib/python3.10/site-packages/aiogram/dispatcher/handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "/home/local/.local/lib/python3.10/site-packages/aiogram/dispatcher/dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "/home/local/.local/lib/python3.10/site-packages/aiogram/dispatcher/handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "/home/local/Projects/helpdesk-bot/handlers/tasks_stat.py", line 55, in question_handler
duration += int(item['timeEstimate'])
TypeError: string indices must be integers