电报机器人不发送带有“<”、“>”符号的消息

专家
response=requests.post("https://api.telegram.org/<botToken>/sendmessage?chat_id=12345&parse_mode=HTML&text={}".format(" &gt;")) 
print(response.text) 

该消息>不会在移动设备上发送并response.text打印:

{"ok":false,"error_code":400,"description":"Bad Request: message must be non-empty"} 

我已经关注了电报官方 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 &lt;, > with &gt; and & with &amp;).
0石0

使用 python 转换文本,urllib.parse.quote_plus(string)这样特殊字符就不会干扰 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(" &gt;")))
print(response.text)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章