Reputation: 93
I have a telegram bot, but over time or immediately upon startup it gets a connection error. To write a bot, I use the "telebot" library.
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bottoken/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x02FB6910>, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))
How to handle this error and try to turn on the bot until it turns on?
Upvotes: 1
Views: 2032
Reputation: 2026
Try the following - use ConnectionError
from requests.eceptions
from requests.exceptions import ConnectionError
try:
Bot working and doing stuff
except ConnectionError as e:
log e
start Bot()
Upvotes: 1