首页 > 解决方案 > 向电报机器人发送消息,错误:{'ok': False, 'error_code': 400, 'description': 'Bad Request: chat not found'}

问题描述

import requests

def telegram_bot_sendtext(bot_message):
    bot_token = '101XXXXXX:AAF50Nh75K0jf0cKN16SFpTqge2gijqMsAUV'
    bot_chatID = 'XXXXXXXX'
    send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message

    response = requests.get(send_text)

    return response.json()


test = telegram_bot_sendtext("Testing Telegram bot")
print(test)

我不明白为什么这不起作用,当我在我的网络浏览器中使用我的机器人令牌来获取更新时,它工作得很好。我立即尝试使用相同的凭据以及我的 chat_id 向同一个机器人发送消息,但我收到了该错误。

标签: python-3.xbotstelegram-bot

解决方案


推荐阅读