L
L
LeakySpoon2022-01-21 20:52:38
Python
LeakySpoon, 2022-01-21 20:52:38

How to correctly form a POST request?

When I try to attach ReplyKeyboard markup, it doesn't send me a keyboard, the message text stops sending too. How can I correctly formulate a POST request?

def send_message(chat_id, text, reply_markup=None):
    method = "sendMessage"
    token = get_from_env("TOKEN")
    url = f"https://api.telegram.org/bot{token}/{method}"
    data = {"chat_id": chat_id, "text": text, "reply_markup": reply_markup}
    requests.post(url, data)

send_message(
                chat_id=request.json["message"]["from"]["id"],
                text='Неправильно, это же ' + str(answer).lower() + '. Стыдно не знать!',
                reply_markup={"keyboard": }
                )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-01-21
@LeakySpoon

Need to convert this dictionary to JSON string

imprort json

data = {"chat_id": chat_id, "text": text, "reply_markup": json.dumps(reply_markup)}

Or initially send all this as application/json
data = {"chat_id": chat_id, "text": text, "reply_markup": reply_markup}
requests.post(url, json=data)

For the future - read the query response

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question