gpt4 book ai didi

python-3.x - Telegram Bot 错误 - telegram.error.BadRequest : Button_data_invalid

转载 作者:行者123 更新时间:2023-12-04 02:54:55 26 4
gpt4 key购买 nike

我正在尝试使用 telegram 制作 Telegram Bot 和 telegram.ext Python 上的库。我尝试通过 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
你认为它可能是什么?

最佳答案

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

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

关于python-3.x - Telegram Bot 错误 - telegram.error.BadRequest : Button_data_invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53440654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com