Reputation: 187
response=requests.post("https://api.telegram.org/<botToken>/sendmessage?chat_id=12345&parse_mode=HTML&text={}".format(" >"))
print(response.text)
The message >
doesn't get sent on mobile and response.text
prints :
{"ok":false,"error_code":400,"description":"Bad Request: message must be non-empty"}
I have followed the telegram official api https://core.telegram.org/bots/api#html-style -
All <, > and & symbols that are not a part of a tag or an HTML entity must be replaced with the corresponding HTML entities (< with <, > with > and & with &).
Upvotes: 1
Views: 2655
Reputation: 43983
Convert your text using the python urllib.parse.quote_plus(string)
so the special characters won't interfere with the url;
import requests
from urllib.parse import quote_plus
response=requests.post("https://api.telegram.org/bot<TOKEN>/sendmessage?chat_id=12345&parse_mode=HTML&text={}".format(quote_plus(" >")))
print(response.text)
Upvotes: 3