Al_Petrushin
@Al_Petrushin
Люблю шахматы, книги, спорт и немного программирую

Query is too old and response timeout expired or query id is invalid, как решить?

Всем привет! Возникает данная ошибка:
Код ошибки
PS C:\Users\zaggg\Desktop\WiseBot> & "C:/Program Files/Python311/python.exe" c:/Users/zaggg/Desktop/WiseBot/main.py
Task exception was never retrieved
future: <Task finished name='Task-13' coro=<Dispatcher._process_polling_updates() done, defined at C:\Program Files\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=InvalidQueryID('Query is too old and response timeout expired or query id is invalid')>
Traceback (most recent call last):
  File "C:\Program Files\Python311\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:\Program Files\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
    return await asyncio.gather(*tasks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 283, in process_update
    return await self.callback_query_handlers.notify(update.callback_query)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\zaggg\Desktop\WiseBot\main.py", line 47, in hour_changer
    await bot.answer_callback_query('Выбери удобное время')
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\bot\bot.py", line 2758, in answer_callback_query
    return await self.request(api.Methods.ANSWER_CALLBACK_QUERY, payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\bot\base.py", line 236, in request
    return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\bot\api.py", line 140, in make_request
    return check_result(method, response.content_type, response.status, await response.text())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\bot\api.py", line 115, in check_result
    exceptions.BadRequest.detect(description)
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\utils\exceptions.py", line 140, in detect
    raise err(cls.text or description)
aiogram.utils.exceptions.InvalidQueryID: Query is too old and response timeout expired or query id is invalid
Task exception was never retrieved
future: <Task finished name='Task-17' coro=<Dispatcher._process_polling_updates() done, defined at C:\Program Files\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=InvalidQueryID('Query is too old and response timeout expired or query id is invalid')>
Traceback (most recent call last):
  File "C:\Program Files\Python311\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:\Program Files\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
    return await asyncio.gather(*tasks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 283, in process_update
    return await self.callback_query_handlers.notify(update.callback_query)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\zaggg\Desktop\WiseBot\main.py", line 58, in hour_changer
    await bot.answer_callback_query('Выбери удобное время')
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\bot\bot.py", line 2758, in answer_callback_query
    return await self.request(api.Methods.ANSWER_CALLBACK_QUERY, payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\bot\base.py", line 236, in request
    return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\bot\api.py", line 140, in make_request
    return check_result(method, response.content_type, response.status, await response.text())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\bot\api.py", line 115, in check_result
    exceptions.BadRequest.detect(description)
  File "C:\Program Files\Python311\Lib\site-packages\aiogram\utils\exceptions.py", line 140, in detect
    raise err(cls.text or description)
aiogram.utils.exceptions.InvalidQueryID: Query is too old and response timeout expired or query id is invalid

Нажимаю я сразу, без задержки, и ботом пользуюсь только я сам, то есть ошибка в хендлере
Привожу участок кода, с которым возникает проблема

@dp.message_handler(commands=["start"])
async def start_message(message:types.Message):
    await message.reply('<i> Привет, {0.first_name}</i>'.format(message.from_user))
    await bot.send_photo(message.from_user.id,photo=open(r'C:\Users\zaggg\Desktop\WiseBot\му.jpg','rb'))
    await bot.send_photo(message.from_user.id,photo=open(r'C:\Users\zaggg\Desktop\WiseBot\мт.jpg','rb'))
    bt1=InlineKeyboardButton(text='Утром', callback_data= 'daypart|утро')
    bt2=InlineKeyboardButton(text='Днём', callback_data= 'daypart|день')
    bt3=InlineKeyboardButton(text='Вечером', callback_data= 'daypart|вечер')
    daypart=InlineKeyboardMarkup().add(bt1,bt2,bt3)
    await message.reply('Когда ты хочешь получать мои сообщения?', reply_markup= daypart)



@dp.callback_query_handler(lambda c: c.data.split('|')[0]=='daypart')
async def hour_changer(callback_query: types.CallbackQuery):
    if callback_query.data == 'daypart|утро':
        m_bt1= InlineKeyboardButton(text='06:00', callback_data ='current_time|06:00')
        m_bt2= InlineKeyboardButton(text='07:00', callback_data ='current_time|07:00')
        m_bt3= InlineKeyboardButton(text='08:00', callback_data ='current_time|08:00')
        m_bt4= InlineKeyboardButton(text='09:00', callback_data ='current_time|09:00')
        m_bt5= InlineKeyboardButton(text='10:00', callback_data ='current_time|10:00')
        m_bt6= InlineKeyboardButton(text='11:00', callback_data ='current_time|11:00')
        m_bt7= InlineKeyboardButton(text='12:00', callback_data ='current_time|12:00')
        keyboard_morning=InlineKeyboardMarkup().add(m_bt1,m_bt2,m_bt3,m_bt4,m_bt5,m_bt6,m_bt7)
        await bot.answer_callback_query('Выбери удобное время')
        await bot.send_message(callback_query.from_user.id,'Выбери удобное время', reply_markup= keyboard_morning)
           
    elif callback_query.data == 'daypart|день':
        d_bt1=InlineKeyboardButton(text='13:00', callback_data = 'current_time|13:00')
        d_bt2=InlineKeyboardButton(text='14:00', callback_data = 'current_time|14:00')
        d_bt3=InlineKeyboardButton(text='15:00', callback_data = 'current_time|15:00')
        d_bt4=InlineKeyboardButton(text='16:00', callback_data = 'current_time|16:00')
        d_bt5=InlineKeyboardButton(text='17:00', callback_data = 'current_time|17:00')
        d_bt6=InlineKeyboardButton(text='18:00', callback_data = 'current_time|18:00')
        keyboard_day= InlineKeyboardMarkup().add(d_bt1,d_bt2,d_bt3,d_bt4,d_bt5,d_bt6)
        await bot.answer_callback_query('Выбери удобное время')
        await bot.send_message(callback_query.from_user.id,'Выбери удобное время', reply_markup= keyboard_day)

    elif callback_query.data == 'daypart|вечер':
        e_bt1=InlineKeyboardButton('19:00', callback_data= 'current_time|19:00')
        e_bt2=InlineKeyboardButton('20:00', callback_data= 'current_time|20:00')
        e_bt3=InlineKeyboardButton('21:00', callback_data= 'current_time|21:00')
        e_bt4=InlineKeyboardButton('22:00', callback_data= 'current_time|22:00')
        e_bt5=InlineKeyboardButton('23:00', callback_data= 'current_time|23:00')
        keyboard_evening=InlineKeyboardMarkup().add(e_bt1,e_bt2,e_bt3,e_bt4,e_bt5)
        await bot.answer_callback_query('Выбери удобное время')
        await bot.send_message(callback_query.from_user.id,'Выбери удобное время', reply_markup= keyboard_evening)
  • Вопрос задан
  • 199 просмотров
Решения вопроса 1
@o5a
Потому что answer_callback_query первым параметром принимает id, а не текст.
await bot.answer_callback_query(callback_query.id, 'Выбери удобное время')
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

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