I sending post to teleram Channel via Requests lib and i need to add Enter for better formate in channel and i use n
at the end of lines but it dosen’t work is there any idea for this
This is my code
import requests
def Telegram_channel (x):
url = "https://api.telegram.org/bot<token>/sendMessage"
data = {"chat_id":"-USER_id", "text":x}
r = requests.post(url, json=data)
x = ">>>> length of Tv packs banned in Database : n"
x = x,">>>> Torrent Link DB value ",torrent_link,'n'
Telegram_channel (x)
and the result is :
>>>> length of Tv packs banned in Database n>>>> Torrent Link DB value n
but it should be like this
>>>> length of Tv packs banned in Database
>>>> Torrent Link DB value
2
Answers
Try below :
Basically the parameter you need to send in this api, in query params, and actually you are sending them in body, so please send in query string and enjoy coding.
URL :
https://api.telegram.org/bot%5BBOT_API_KEY%5D/sendMessage?chat_id=%5BMY_CHANNEL_NAME%5D&text=%5BMY_MESSAGE_TEXT%5D
METHOD : GET
where:
your bot
@my_channel_name)
(URL-encoded)
You are actually creating a
tuple
instead ofstr
(whichtext
JSON parameter should be):Output:
Requests lib cannot treat it correctly to construct an HTTP request, so you lose line breaks.
Why not use string formatting?
Chat output: