如何处理启用电报机器人的错误



我有一个电报机器人,但随着时间的推移或启动后立即出现连接错误。要编写机器人,我使用"远程机器人"库。

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)'))

如何处理此错误并尝试打开机器人直到它打开?

尝试以下操作 - 使用requests.eceptions中的ConnectionError

from requests.exceptions import ConnectionError
try:
   Bot working and doing stuff
except ConnectionError as e:
   log e
   start Bot()

最新更新