I
I
Ivan Yakushenko2019-06-09 16:09:42
Python
Ivan Yakushenko, 2019-06-09 16:09:42

Why isn't more than one button created with pyTelegramBotAPI?

Keyboard send code:

@bot.message_handler(content_types=['text'])
def send_text(message):
    query = api_query(message.text)
    if query is not None:
        keyboard = types.InlineKeyboardMarkup()
        for item in query:
            print(item)
            keyboard.add(types.InlineKeyboardButton(text=item, callback_data=item))
        bot.send_message(message.from_user.id, text='Вот, что я нашел:', reply_markup=keyboard)
    else:
        bot.send_message(message.from_user.id, 'Ой, мне ничего не удалось найти. Ты точно ввел(а) правильное название?')

The query stores the search results, for example:
['Чернобыль: Зона отчуждения (2014)', 'Чернобыльские джунгли. 20 лет без человека (2008)', 'Чернобыль (2019)']

When I try to run the code, the error is:
telebot.apihelper.ApiException: A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:
[b'{"ok":false,"error_code":400,"description":"Bad Request: BUTTON_DATA_INVALID"}']

Moreover, if there is only 1 element in the query, then the button is sent without problems.
How correctly in my case I need to form a keyboard?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Yakushenko, 2019-06-09
@kshnkvn

Actually, as always - the fool inattentively read the documentation and ran to the toaster:
The code is working, only in callback_data I have exceeded the API limit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question