7

I'm trying to make a telegram bot with the telegram and telegram.ext libraries on Python. I try to pass callback_data for a button as a parameter for inline keyboard, but when it comes to add the keyboard as reply_markup, it sends the following error:

Traceback (most recent call last): File "C:\Users\micke\AppData\Local\Programs\Python\Python36-32\lib\site-packages\telegram\ext\dispatcher.py", line 279, in process_update handler.handle_update(update, self) File "C:\Users\micke\AppData\Local\Programs\Python\Python36-32\lib\site-packages\telegram\ext\callbackqueryhandler.py", line 143, in handle_update return self.callback(dispatcher.bot, update, **optional_args) File ".\__init__.py", line 121, in button reply_markup=reply_markup File "C:\Users\micke\AppData\Local\Programs\Python\Python36-32\lib\site-packages\telegram\bot.py", line 60, in decorator result = func(self, *args, **kwargs) File "C:\Users\micke\AppData\Local\Programs\Python\Python36-32\lib\site-packages\telegram\bot.py", line 85, in decorator result = self._request.post(url, data, timeout=kwargs.get('timeout')) File "C:\Users\micke\AppData\Local\Programs\Python\Python36-32\lib\site-packages\telegram\utils\request.py", line 273, in post **urlopen_kwargs) File "C:\Users\micke\AppData\Local\Programs\Python\Python36-32\lib\site-packages\telegram\utils\request.py", line 210, in _request_wrapper raise BadRequest(message) telegram.error.BadRequest: Button_data_invalid

The code is the following:

p1 = "%s(@%s)"%(query.from_user.first_name,query.from_user.username) text = "<b>⚔Duel</b>\nChallenger %s is ready!\nWaiting for an opponent..."%p1 args = '{"next":"player2","p1":"%s","text":"%s"}'%(p1,text) reply_markup = InlineKeyboardMarkup(kb.kb(op = "data",args = args)) bot.edit_message_text( text=text, inline_message_id=query.inline_message_id, parse_mode=ParseMode.HTML, reply_markup=reply_markup )

Also, the code for the keyboard is:

class kb: def kb(op = None, args = None): if op == 'data': keyboard = [[InlineKeyboardButton("Join", callback_data = args)]]

I don't really know where am I mistaken. It works well when instead of args I assign static text to callback_data

What do you think it could be?

Mickey Rodriguez
  • 71
  • 1
  • 1
  • 2

1 Answers1

16

Probably data size, you passing, is exceeding the maximum allowed bytes of 64. Here is the docs. You can get size of data in bytes as followed.

len('YOUR DATA'.encode('utf-8'))
Darkhan ZD
  • 580
  • 8
  • 14