I’ve got following error while trying to send a message to a specific telegram channel:
TimedOut: Timed out
The read operation timed out
the method which I used from python-telegram-bot was send_message
.
Although my bot got this error but it still sent the message to the channel and because I did not catch that exception all data from the message was lost but I really need to remove my messages from that channel after a specific period of time.
Is this OK that the bot sent the message even though it got Timed Out? How can I prevent this from happen again or remove this kind of messages from the channel after being sent?
2
Answers
Time out errors mean that TG didn’t send a response to your
send_message
request quick enough. It does not necessarily mean that the request wasn’t processed – that’s why the message may still be sent. However, without response from TG, you don’t have the message id of the resulting message and it will be hard to impossible to delete it.You can try to increase the time that PTB waits for a response from TG. THis can be done in different ways:
timeout
parameter ofsend_message
Defaults.timeout
, if you’re using PTBsDefaults
setuprequest_kwargs
that you pass toUpdater
You may want to have a look at this wiki page on networking.
Disclaimer: I’m currently the maintainer of
python-telegram-bot
After a couple of hours reading here and there, and passing timeout=30 to
context.bot.send_audio
and getting an error that saysunknown parameter
even thoughsend_audio
‘s docs clearly states it takes atimeout
param, I found that you can fix this by passing the timeouts to the Application upon building it:This fixed my bot. Hope this helps you as well.