电报Bot错误-telegram.error.BadRequest:Button_data_invalid

时间:2018-11-23 04:28:39

标签: python-3.x telegram telegram-bot

我正在尝试使用Python上的telegramtelegram.ext库制作一个电报机器人。我尝试将按钮的callback_data传递为嵌入式键盘的参数,但是当将键盘添加为reply_markup时,它将发送以下错误:

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

代码如下:

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 )

此外,键盘代码是:

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

我真的不知道我在哪里弄错了。当我将静态文本分配给args

而不是callback_data时,它会很好地工作

您认为这可能是什么?

1 个答案:

答案 0 :(得分:3)

您传递的数据大小可能超过了允许的最大字节数64。 这是docs。 您可以按以下方式获取以字节为单位的数据大小。

len('YOUR DATA'.encode('utf-8'))