T
T
Trefame2020-07-26 00:44:53
Python
Trefame, 2020-07-26 00:44:53

How to accept a POST request in python?

Hello! I am writing a bot for sending SMS messages using the API of third-party services, for the service that I use when sending messages, you can specify a CallbackURL to which a POST request with message data will be sent after it is delivered. In PHP, it was, of course, very simple, but I decided to try to switch to Python for personal interest and I can’t figure out how to implement it (I’m talking about $ _POST). I have already been told a lot of terrible things, and about the fact that it will be necessary to raise almost three servers, there is a web socket, here is a web socket, is it possible to somehow implement this all in the same way as PHP, of course, not in one line, but without raising additional servers and others?

To write a bot, I use the Aiogram library, and it must also be in one application, that is, a bot, so that after the SMS delivery response arrives, the user receives a message with an inline button, and the bot processes this button as I need

Of the solutions, I found only Flask, Django, I tried to run it, it does not fit with long polling, it just starts the Flask server, django is a very cumbersome and heavy option, it is hardly convenient to use

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SKEPTIC, 2020-07-26
@Trefame

You either need to use a ready-made framework (Django, Flask).
Or use http server from python, for example, https://docs.python.org/3/library/http.server.html .
Or write your web server on sockets.
Or use PHP and don't bother.

Of the solutions, I found only Flask, Django, I tried to run it, it does not fit with long polling, it just starts the Flask server, django is a very cumbersome and heavy option, it is hardly convenient to use

In theory, this should be run in different scripts, if you need interaction between scripts, then use message brokers, you can queue or just sockets.

A
Alexander, 2020-07-26
@morz45

Why, if you have a server, run long polling, read about webhooks in the telegram, aiogram can work on them too. That is, telegrams will send you the same post requests as the payment. All you need is one server, you accept telegram hooks on one route, and payment hooks on the other. If you write on an asynchronous aiogram, then why do you need synchronous Flask or Dzhang ... look towards the now popular FastAPI.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question