H
H
Hikanosu2021-05-04 17:22:30
MySQL
Hikanosu, 2021-05-04 17:22:30

AIOgram, what is the best way to update the mailing code so that it does not stop due to Flood control?

Initially, I wrote the code for the mailing list, but even with a small number of users in the mailing list, it stopped due to Flood control. Rewrote the mailing list as follows and increased the time out between messages:

...
            for user in row:
                try:
                    await bot.send_message(chat_id=user[0], text=data['mailing_text'])
                except:
                time.sleep(0.1)
       ...

And this was enough for a certain period of time. But when there were more than 3,000 people in the mailing list, a new problem appeared:
Flood control exceeded. Retry in n seconds.

Would it be enough just to increase the time out between messages to get rid of this error? Or are there better fixes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
idShura, 2018-10-05
@idShura

Delimiter problem, try this:

DELIMITER | 
CREATE TRIGGER `base`.`after_table`
AFTER INSERT ON `table` FOR EACH ROW BEGIN
INSERT INTO `table2` SET `name`='text';
END |
DELIMITER ;

S
shurshur, 2021-05-04
@Hikanosu

Do not use time.sleep in asynchronous code, it will block the event loop! Instead, you should use the asynchronous version of asyncio.sleep.
In essence, with this code, 10 sends per second will be made, and officially the limit is 30 per second. But it would be better to additionally catch the exception with flood control and use it to do an additional sleep for at least 1 second, or even a little more, so that the counter of the number of attempts on the Telegram side is reset during this time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question