@Sverepay

Почему возникает ошибка с базой данных?

Вот ошибка
Task exception was never retrieved
future: at C:\Users\Toshiba\AppData\Local\Programs\Python\Python37\lib\site-packages\ai
ogram\dispatcher\dispatcher.py:407> exception=ValueError('parameters are of unsu
pported type')>
Traceback (most recent call last):
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python37\lib\site-package
s\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(up
dates, fast)):
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python37\lib\site-package
s\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python37\lib\site-package
s\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python37\lib\site-package
s\aiogram\dispatcher\dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python37\lib\site-package
s\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "main.py", line 18, in start
if not db.user_exists(message.from_user.id):
File "C:\Users\Toshiba\Desktop\FastShop\db.py", line 10, in user_exists
result = self.cursor.execute("SELECT * FROM `users` WHERE `user_id` = ?", (u
ser_id)).fetchall()
ValueError: parameters are of unsupported type

Здесь я проверяю есть ли пользователь в бд
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
    if not db.user_exists(message.from_user.id):
        db.add_user(message.from_user.id)
    photo = InputFile("media/main.jpg")
    text = bottext.maintext

    await bot.send_photo(chat_id=message.chat.id, photo=photo, caption=text, reply_markup=nav.mainMenu)


База даныйх
import sqlite3

class Database:
    def __init__(self, db_file):
        self.connection = sqlite3.connect(db_file)
        self.cursor = self.connection.cursor()

    def user_exists(self, user_id):
        with self.connection:
            result = self.cursor.execute("SELECT * FROM `users` WHERE `user_id` = ?", (user_id)).fetchall()
            return bool(len(result))
    
    def add_user(self, user_id):
        with self.connection:
            self.cursor.execute("INSERT INTO `users` (`user_id`) VALUES (?)", (user_id))

    def user_money(self, user_id):
        with self.connection:
            result = self.cursor.execute("SELECT `money` FROM `users` WHERE `user_id` = ?", (user_id)).fetchmany(1)
            return int(result[0][0])

    def set_money(self, user_id, money):
        with self.connection:
            return self.cursor.execute("UPDATE `users` SET `money` = ? WHERE `user_id` = ?", (money, user_id))
  • Вопрос задан
  • 64 просмотра
Пригласить эксперта
Ваш ответ на вопрос

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

Похожие вопросы