Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python电报机器人如何通过url发送InlineKeyboard_Python_Telegram_Telegram Bot_Python Telegram Bot - Fatal编程技术网

Python电报机器人如何通过url发送InlineKeyboard

Python电报机器人如何通过url发送InlineKeyboard,python,telegram,telegram-bot,python-telegram-bot,Python,Telegram,Telegram Bot,Python Telegram Bot,试图发送带有回拨键Bord的邮件,但效果不佳。给我打电话 TypeError: must be str, not ReplyKeyboardMarkup 找不到任何正确的例子 keyboard = [[InlineKeyboardButton("Выполнено", callback_data='Done')], [InlineKeyboardButton("MAC", callback_data='MAC'), Inline

试图发送带有回拨键Bord的邮件,但效果不佳。给我打电话

TypeError: must be str, not ReplyKeyboardMarkup
找不到任何正确的例子

keyboard = [[InlineKeyboardButton("Выполнено", callback_data='Done')],
                [InlineKeyboardButton("MAC", callback_data='MAC'),
                 InlineKeyboardButton("Phone", callback_data='Phone'),
                 InlineKeyboardButton("История", callback_data='History')]]
    reply_markup = ReplyKeyboardMarkup(keyboard)
    requests.post(url='https://api.telegram.org/bot{blah}/'
                      'sendMessage?chat_id=' + str(query.message.chat_id) + '&text="TEST"&reply_markup=' + reply_markup)

首先,您应该使用
InlineKeyboardMarkup
而不是
ReplyKeyboardMarkup
来创建由
InlineKeyboardButton
s组成的标记对象

然后,您可能应该简单地使用
bot
对象,通过
bot.send\u message(query.message.chat\u id,'TEST',reply\u markup=reply\u markup)
发送消息

最后,如果确实需要使用
请求
执行手动HTTP请求,则应在
请求.post()的
数据中提供参数

import json
import requests
from telegram import InlineKeyboardButton, InlineKeyboardMarkup

keyboard = [[InlineKeyboardButton("Выполнено", callback_data='Done')],
            [InlineKeyboardButton("MAC", callback_data='MAC'),
             InlineKeyboardButton("Phone", callback_data='Phone'),
             InlineKeyboardButton("История", callback_data='History')]]
reply_markup = InlineKeyboardMarkup(keyboard)

data = {"chat_id": query.message.chat_id,
        "text": "TEST", 
        "reply_markup": json.dumps(reply_markup.to_dict())}

requests.post(url='https://api.telegram.org/bot{blah}/sendMessage', data=data)