Reputation: 357
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?
Upvotes: 3
Views: 16301
Reputation: 71
I had the same issue where the message was sent but I received an "Timed out" error. I used the send_media_group
method and solved the problem by adding the write_timeout=20
parameter. For more details, please refer to the following page: LINK.
edit:
The problem is still not resolved. I'm trying with different values for write_timeout=30
and read_timeout=5
, so I'll report back. The default value for write_timeout is 20.
edit2:
The code with parameters write_timeout=35 and read_timeout=20
is now functioning, but I encountered a problem with the "Flood control exceeded. Retry in 12 seconds" error, which I resolved by "catching" the error. When it occurs, I use time.sleep(60)
and attempt to resend the message.
Upvotes: 1
Reputation: 2624
After a couple of hours reading here and there, and passing timeout=30 to context.bot.send_audio
and getting an error that says unknown parameter
even though send_audio
's docs clearly states it takes a timeout
param, I found that you can fix this by passing the timeouts to the Application upon building it:
application = ApplicationBuilder()
.token(bot_data["token"])
.read_timeout(30)
.write_timeout(30)
.build()
This fixed my bot. Hope this helps you as well.
Upvotes: 10
Reputation: 7050
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 of send_message
Defaults.timeout
, if you're using PTBs Defaults
setuprequest_kwargs
that you pass to Updater
You may want to have a look at this wiki page on networking.
Disclaimer: I'm currently the maintainer of python-telegram-bot
Upvotes: 9