将 python 个计算值发送到电报
Sending python computed values to telegram
我刚刚在 python 中创建了一个电报机器人,我想将我在 python 中分析的数据结果以特殊格式发送到电报频道,这里是一个示例我要发送的内容:
a = '#N' + game_to_analyse['Id_number'] + ': ' +'54783355882'
但是当我尝试将此值 'a' 发送到我的电报频道时,我在 phone 或电报桌面应用程序上只收到 "
作为消息。
有什么问题?
#
大概是messing with your url
解决方案:
urlencode()
查询参数:
from urllib.parse import urlencode, quote_plus
data = {
'text' : '#N12345:6789',
'chat_id': myChatId,
'parse_mode' : 'MarkDown'
}
encodedData = urlencode(data, quote_via=quote_plus)
url = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?' + encodedData
response = requests.get(url)
我刚刚在 python 中创建了一个电报机器人,我想将我在 python 中分析的数据结果以特殊格式发送到电报频道,这里是一个示例我要发送的内容:
a = '#N' + game_to_analyse['Id_number'] + ': ' +'54783355882'
但是当我尝试将此值 'a' 发送到我的电报频道时,我在 phone 或电报桌面应用程序上只收到 "
作为消息。
有什么问题?
#
大概是messing with your url
解决方案:
urlencode()
查询参数:
from urllib.parse import urlencode, quote_plus
data = {
'text' : '#N12345:6789',
'chat_id': myChatId,
'parse_mode' : 'MarkDown'
}
encodedData = urlencode(data, quote_via=quote_plus)
url = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?' + encodedData
response = requests.get(url)