从python发送请求到电报时出现错误400

时间:2021-01-26 03:36:12

标签: python telegram

从 python 向电报发送请求时出现 400 错误。

代码如下:

bot_message = message
bot_token = 'xxx'
bot_chatID = 'xxx'
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)

这是导致错误的消息:

sharashahira 2021-01-25 10:37:50 @CIMB_Assists Mana ni kata sampai pkul 4;45pm. Sampai sekaranf error. Boikot cimb clicks app?

它得到了 "emote" ,所以我在发送到电报时得到了 400。

这是错误

{"ok":false,"error_code":400,"description":"Bad Request: can't parse entities: Can't find end of the entity starting at byte offset 17"}

1 个答案:

答案 0 :(得分:0)

<块引用>

无法找到从字节偏移 17 开始的实体结尾"

此错误是由以下原因引起的 MarkDown 错误引起的:@CIMB_Assists

_ 开始一个下划线语法,但永远不会结束。 Telegram 无法发送这些消息。

有两种方法可以解决这个问题;

  1. 删除 MarkDown,以 HTML 格式发送消息:

    '&parse_mode=HTML&text=' + bot_message
    
  2. 从消息中删除 _

    sharashahira 2021-01-25 10:37:50 @CIMBAssists Mana ni kata sampai pkul 4;45pm. Sampai sekaranf error. Boikot cimb clicks app?