A
A
Alexander Karadiaur2021-09-08 13:22:39
Python
Alexander Karadiaur, 2021-09-08 13:22:39

Error: not found c. How to solve problems?

The code:

@bot.callback_query_handler(lambda c: c.data == "aim_confirm")
def aim_confirm(update, c):
    global numbers
    userID = c.from_user.id  # ID пользователя
    chatID = c.message.chat.id  # ID чата с пользователем
    query = update.callback_query

    try:
        if numbers != []:
            amount = int(''.join(map(str, numbers)))
            numbers = []

            db.changeaim(userID, amount)

            bot.edit_message_text('*Успешно*', c.message.chat.id, c.message.id,
                                parse_mode='Markdown',
                                reply_markup=InlineKeyboardMarkup(ib.back))
        else:
            bot.answer_callback_query(callback_query_id=query.id, text = 'Введите число!', show_alert=True)
    except Error as err:
        print(err)


Mistake:
Traceback (most recent call last):
  File "C:\Users\sasha\Desktop\проекты\финансист (открыто)\код2.0\bot.py", line 330, in <module>
    bot.polling()
  File "C:\Users\sasha\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 619, in polling
    self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout, allowed_updates)
  File "C:\Users\sasha\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 678, in __threaded_polling
    raise e
  File "C:\Users\sasha\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 641, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "C:\Users\sasha\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 130, in raise_exceptions
    raise self.exception_info
  File "C:\Users\sasha\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 82, in run
    task(*args, **kwargs)
TypeError: aim_confirm() missing 1 required positional argument: 'c'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Karadiaur, 2021-09-08
@twiwter

It is necessary to remove updateand instead callback_query_id=query.idwrite callback_query_id=с.id, but query = update.callback_queryremove.

S
Stefan, 2021-09-08
@MEDIOFF

def aim_confirm(update, c):
    ...

What is this "update" you are passing into the function? callback_handler function takes 1 argument, callback_query itself, remove update

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question