0

I just created a telegram bot in python and I want to be sending the results of the data I analyse in python to a telegram channel in a special format, here is an sample of what I would like to send:

a = '#N' + game_to_analyse['Id_number'] + ': ' +'54783355882'

But when I try to send this value 'a' to my telegram channel, I only get " as message on my phone or telegram desktop app. What is the issue?

Pozeidon
  • 107
  • 1
  • 14
  • 1
    P.S. I just realized its the '#' that is causing the problem, is there any way to remedy to this without removing the '#'? – Pozeidon Mar 17 '20 at 16:33

1 Answers1

1

The # is probably messing with your url

Solution:

urlencode() the query params:

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)
0stone0
  • 34,288
  • 4
  • 39
  • 64