When I try to send a Poll to a chat I receive the following error:
{'ok': False, 'error_code': 400, 'description': "Bad Request: can't parse options JSON object"}
Regarding to https://core.telegram.org/bots/api#sendpoll the “options” have to be an array out of strings, which obviously doesn’t work.
This is the script I built:
import json, requests
telegram_poll_url = 'https://api.telegram.org/botXXXX:YYYY/sendPoll'
telegram_poll_data = {'chat_id': XXXX, 'options': ["5 Minuten", "10 Minuten"], 'question': "Wann bist hier?", 'is_anonymous': False}
response = requests.post(telegram_poll_url, telegram_poll_data).json()
print(response)
Edit: This also doesnt work
options = ["5 Minuten", "10 Minuten"]
telegram_poll_data = {
'chat_id': -321158590,
'options': options,
'question': "Wann bist du im FF Haus?",
'is_anonymous': False
}
response = requests.post(telegram_poll_url, telegram_poll_data).json()
3
Answers
Parse your options list to JSON.
GET
I had the same problem until I realized I was supposed to send serialized JSON data through the
json
requests.post()
parameter instead of the defaultdata
:This way it would actually use the
application/json
Content-Type and allow the API server to properly decode the sendPoll fields.Use the following
i.e.
json.dumps(options)