To send a message to Telegram, I use this template:
import requests
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"}
urlphoto = f'http://127.0.0.1:0001/Home/Site%20de%20Trabalho%20-%20Home.html'
botalert = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
chatalert = 'yyyyyyyyyyyyyyyy'
urlalert = f"https://api.telegram.org/bot" + botalert + "/sendMessage?text=" + urlphoto + "&chat_id=" + chatalert + "&parse_mode=HTML"
requests.get(urlalert, headers=headers)
But when the message is sent, the link received there does not come together as the %20
is converted into spaces:
How should I proceed so that the link is delivered perfectly like that:
http://127.0.0.1:0001/Home/Site%20de%20Trabalho%20-%20Home.html
3
Answers
Try this:
You can define urlphoto like this:
This will print the percent sign with 20 after it.
Use a parameters dictionary, and the parameters will be encoded correctly for you: