Написал бота. Когда подхожу к последнему стейту возникает ошибка:
Updates were skipped successfully.
Data after adding name: FSMContextProxy state = 'NewOrder:name', data = {'name': 'Математика'}
Task exception was never retrieved
future: <Task finished name='Task-21' coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\Dell1\Desktop\bdbot3\venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=KeyError('desc')>
Traceback (most recent call last):
File "C:\Users\Dell1\Desktop\bdbot3\venv\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 "C:\Users\Dell1\Desktop\bdbot3\venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell1\Desktop\bdbot3\venv\Lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell1\Desktop\bdbot3\venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell1\Desktop\bdbot3\venv\Lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\Dell1\Desktop\bdbot3\main.py", line 44, in add_item_desc
await db.add_item(state)
File "c:\Users\Dell1\Desktop\bdbot3\database.py", line 11, in add_item
cur.execute('INSERT INTO items (name, desc) VALUES (?, ?)',(data['name'], data['desc']))
~~~~^^^^^^^^
File "C:\Users\Dell1\Desktop\bdbot3\venv\Lib\site-packages\aiogram\dispatcher\storage.py", line 439, in __getitem__
return self._data[item]
~~~~~~~~~~^^^^^^
KeyError: 'desc'
это код файла main:
@dp.message_handler(state = NewOrder.name)
async def add_item_name(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['name'] = message.text
await message.answer(f'Опиши индивидуальный проект:')
print(f"Data after adding name: {data}")
await NewOrder.desc.set()
@dp.message_handler(state=NewOrder.desc)
async def add_item_desc(message:types.Message, state: FSMContext):
async with state.proxy() as data:
data['desc'] = message.text
await db.add_item(state)
await message.answer(f'Ты успешно добавил товар')
await state.finish()
@dp.message_handler(text='Добавить')
async def contacts(message: types.Message):
if message.from_user.id == int(ADMIN_ID):
await NewOrder.name.set()
await message.answer(f'Укажи название товара.')
это код файла database:
import sqlite3 as sq
db = sq.connect('list.db')
cur = db.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS items(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, desc TEXT)')
db.commit()
async def add_item(state):
async with state.proxy() as data:
cur.execute('INSERT INTO items (name, desc) VALUES (?, ?)',(data['name'], data['desc']))
db.commit()
не знаю какой тег оставить, потому что не уверен что дело в sqlite