@EVG82

KeyError: 'user_id' как устранить?

import sqlite3 as sq


def sql_start():

    global base, cur
    base = sq.connect('db.db', check_same_thread=False)
    cur = base.cursor()
    if base:
        print('Подключился к БД')
    base.execute('CREATE TABLE IF NOT EXISTS test(user_id, user_name, user_surname, username)')
    base.commit()

async def sql_add_command(state):

    async with state.proxy() as data:
        user_id = data['user_id']
        username = data['username']
        user_surname = data['user_surname']
        user_name = data['user_name']
        cur.execute('INSERT or IGNORE into test(user_id, user_name, user_surname, username) VALUES (?, ?, ?, ?)', (user_id, user_name, user_surname, username))
        base.commit()


выдает ошибку

Traceback (most recent call last):
  File "G:\PYTHON\telebot_test\bot\lib\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 "G:\PYTHON\telebot_test\bot\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
    return await asyncio.gather(*tasks)
  File "G:\PYTHON\telebot_test\bot\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "G:\PYTHON\telebot_test\bot\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
    return await self.message_handlers.notify(update.message)
  File "G:\PYTHON\telebot_test\bot\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "G:\PYTHON\pythonProject123\handlers\partnerbaze1.py", line 38, in get_email
    await sqlite_db.sql_add_command(state)
  File "G:\PYTHON\pythonProject123\data_base\sqlite_db.py", line 17, in sql_add_command
    user_id = data['user_id']
  File "G:\PYTHON\telebot_test\bot\lib\site-packages\aiogram\dispatcher\storage.py", line 439, in __getitem__
    return self._data[item]
KeyError: 'user_id'
  • Вопрос задан
  • 469 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

Похожие вопросы
26 нояб. 2024, в 12:39
15000 руб./за проект
26 нояб. 2024, в 11:39
1000 руб./за проект