You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

python-telegram-bot添加reply_markup报Button_url_invalid错误如何解决?

问题排查与解决方法

核心原因

InlineKeyboardButton构造函数要求除首个text参数外,其余属性必须使用关键字传参。你直接将URL作为第二个位置参数传入时,程序会错误识别为其他属性(如callback_data),导致Telegram服务器校验按钮时找不到有效URL,返回Button_url_invalid错误。

修复代码

key = InlineKeyboardMarkup([
                [InlineKeyboardButton('Google', url='http://www.google.com/')],
                [InlineKeyboardButton('Youtube', url='http://www.youtube.com/')],
                ])
msg = bot.edit_message_reply_markup(chat_id=channel, message_id=msg.message_id, reply_markup=key)

额外校验规则

如果修改后仍报错,可逐一核对以下要求:

  • URL必须带有http://或https://协议头,不可省略协议直接写域名
  • URL不能包含Telegram官方封禁的域名
  • 编辑消息时传入的chat_id、message_id参数正确,对应消息存在且支持编辑

内容的提问来源于stack exchange,提问作者Andrea Pellegrini

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 21:21:01