我有 mp3 的工作 url,并且我正在尝试通过此 url 将音频发送到 Telegram。它有时会起作用,但大多数时候都会出错
"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: failed to get HTTP
URL content"}']"
Run Code Online (Sandbox Code Playgroud)
我不明白为什么,因为我检查了大小和类型,一切都很清楚,我在 Telegram API 文档中找不到更多限制。谁知道错误原因是什么?
链接到 mp3 - http://data3.api.xn--41a.ws/vkp/cs9-5v4.userapi.com/p15/51bdb5ec5899ed.mp3
python-3.x telegram python-telegram-bot telegram-bot telegram-webhook
我正在玩 Python Telegram Bot,我想将先前计算获得的参数传递给我的处理程序,例如:
def my_handler(bot, update, param):
print(param)
def main():
res = some_function()
updater.dispatcher.add_handler(CommandHandler('cmd', my_handler))
Run Code Online (Sandbox Code Playgroud)
如何将参数传递给处理程序?
我正在尝试将 CallbackQueryHandler() 与我的机器人一起使用,但我无法使其适用于我的情况。我尝试的机器人代码与此示例相同:
def start(bot, update):
keyboard = [[InlineKeyboardButton("Option 1", callback_data='1'),
InlineKeyboardButton("Option 2", callback_data='2')],
[InlineKeyboardButton("Option 3", callback_data='3')]]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('Please choose:', reply_markup=reply_markup)
def button(bot, update):
query = update.callback_query
bot.edit_message_text(text="Selected option: %s" % query.data,
chat_id=query.message.chat_id,
message_id=query.message.message_id)
def help(bot, update):
update.message.reply_text("Use /start to test this bot.")
def error(bot, update, error):
logging.warning('Update "%s" caused error "%s"' % (update, error))
# Create the Updater and pass it your bot's token.
updater = Updater(TOKEN)
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CallbackQueryHandler(button))
updater.dispatcher.add_handler(CommandHandler('help', help))
updater.dispatcher.add_error_handler(error)
# Start the Bot …Run Code Online (Sandbox Code Playgroud) 我目前正在使用python-telegram-bot,基本上我想用它实现的是发送这样的电报消息:
因此,该消息包含 2 张以上的照片/视频,下方带有文本消息。
我已经尝试过的:
使用send_message方法发送消息,并包括照片 URL,但它只显示文本下方的 1 张图片
使用send_media_group发送媒体组,但此方法没有caption作为send_photo 的参数。
当我尝试运行我的脚本(我的电报机器人)时,终端中会出现以下内容:
/usr/local/lib/python3.7/dist-packages/python_telegram_bot-12.4.2-
py3.7.egg/telegram/utils/request.py:47: UserWarning: python-telegram-bot is using upstream urllib3.
This is allowed but not supported by python-telegram-bot maintainers.
Run Code Online (Sandbox Code Playgroud)
我做什么?
多谢
我想制作一个按钮,可以从 Telegram 聊天中在浏览器中打开 URL(外部超链接)。目前,我只开发了可点击的操作按钮。
update.message.reply_text(
'Subscribe to us on Facebook and Telegram:',
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton(text='on Facebook', callback_data='Facebook')],
[InlineKeyboardButton(text='on Telegram', callback_data='Telegram')],
])
)
Run Code Online (Sandbox Code Playgroud)
但如何将它们作为链接(带箭头)。我想请求用户分享。
运行后pip install python-telegram-bot,我收到此错误,表示找不到“电报”模块。
在下面pip list我看到我的 python-telegram-bot 软件包安装了版本 13.2
还有其他人收到此错误吗?
我有一个按钮,它应该返回ask_wikipedia函数,所以我使用了CallbackQueryHandler,但是当我想调用ask_wikipedia函数时,我收到一个属性错误!为什么?我该如何修复它?
def Click_Button(update, context) :
query = update.callback_query
if query.data == "Research":
ask_wikipedia(update, context)
query_handler = CallbackQueryHandler(Click_Button)
dispatcher.add_handler(query_handler)
def ask_wikipedia(update, context) :
update.message.reply_text('What do you want to know about ? ')
return About
Run Code Online (Sandbox Code Playgroud)
当我点击按钮时出现此错误
AttributeError: 'NoneType' object has no attribute 'reply_text'
Run Code Online (Sandbox Code Playgroud)
我该如何解决它?
python attributeerror telegram python-telegram-bot telegram-bot
当我执行此操作时发生了这种情况:
updater = Updater('xyaz:testtsttttt-HI', use_context=True)
Run Code Online (Sandbox Code Playgroud)
非常感谢!