Как исправить «TypeError: tuple indices must be integers or slices, not str»?

async def chekc_balance(self, user):
        async with self.pool.acquire() as conn:
            async with conn.cursor() as cur:
                result = await cur.execute("SELECT * FROM profile WHERE uid=%s", user.id)
                row = await cur.fetchall()
                if result == 1:
                    await cur.execute("UPDATE profile SET balance=balance WHERE uid=%s", user.id)
                    return row['balance']

@command(name="кошелёк")
    async def prov(self, ctx):
        user = await self.bot.get_user(ctx.from_id)
        balance = await basa.register.main.chekc_balance(user)
        return await ctx.send(f"В кошельке: {balance}\n"
                              f"На карточке:\n")

Ошибка:
raise CommandInvokeError(exc) from exc vk_botting.exceptions.
CommandInvokeError: 
Command raised an exception: 
TypeError: tuple indices must be integers or slices, not str

Как исправить ошибку?
  • Вопрос задан
  • 1086 просмотров
Решения вопроса 1
tsklab
@tsklab
Здесь отвечаю на вопросы.
TypeError: tuple indices must be integers, not str:
Like the error says, row is a tuple, so you can't do row["pool_number"]. You need to use the index: row[0].

result = await cur.execute("SELECT balance FROM profile WHERE uid=%s", user.id)
  row = await cur.fetchall()
  if result == 1:
                    return row[0]
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы