Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

error 400 when sending request from python to telegram

I got a 400 error while sending a request from python to telegram.

Here is the code:

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)

Here's the message that caused error :

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

It got "emote" , so I got 400 when send to telegram.

This is the error

{"ok":false,"error_code":400,"description":"Bad Request: can't parse entities: Can't find end of the entity starting at byte offset 17"}
question from:https://stackoverflow.com/questions/65895555/error-400-when-sending-request-from-python-to-telegram

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Can't find end of the entity starting at byte offset 17"

This error is caused by a MarkDown error caused by: @CIMB_Assists

The _ starts an underline syntax, but is never closed. Telegram can't send those messages.

There are 2 ways to fix this;

  1. Remove the MarkDown, send the message as HTML:

    '&parse_mode=HTML&text=' + bot_message
    
  2. Remove the _ from the message

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[3] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

57.0k users

...