orenlab / pytmbot

Flexible Telegram bot designed to manage Docker containers, monitor server status, and extend its functionality through a plugin system
https://orenlab.github.io/pytmbot/
MIT License
7 stars 2 forks source link

ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway" #26

Closed AsdertyTreds closed 4 months ago

AsdertyTreds commented 4 months ago

2024-05-14 01:15:09,697 (init.py:1212 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway" 2024-05-14 01:15:09,702 (init.py:1214 MainThread) ERROR - TeleBot: "Exception traceback: Traceback (most recent call last): File "/venv/lib/python3.12/site-packages/telebot/init.py", line 1205, in threaded_polling polling_thread.raise_exceptions() File "/venv/lib/python3.12/site-packages/telebot/util.py", line 111, in raise_exceptions raise self.exception_info File "/venv/lib/python3.12/site-packages/telebot/util.py", line 93, in run task(*args, **kwargs) File "/venv/lib/python3.12/site-packages/telebot/init.py", line 675, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/init__.py", line 647, in get_updates json_updates = apihelper.get_updates( ^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 327, in get_updates return _make_request(token, method_url, params=payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 167, in _make_request json_result = _check_result(method_name, result) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 194, in _check_result raise ApiTelegramException(method_name, result, result_json) telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway " 2024-05-14 01:15:10,083 (init.py:1212 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway" 2024-05-14 01:15:10,085 (init.py:1214 MainThread) ERROR - TeleBot: "Exception traceback: Traceback (most recent call last): File "/venv/lib/python3.12/site-packages/telebot/init.py", line 1205, in threaded_polling polling_thread.raise_exceptions() File "/venv/lib/python3.12/site-packages/telebot/util.py", line 111, in raise_exceptions raise self.exception_info File "/venv/lib/python3.12/site-packages/telebot/util.py", line 93, in run task(*args, *kwargs) File "/venv/lib/python3.12/site-packages/telebot/init.py", line 675, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/init__.py", line 647, in get_updates json_updates = apihelper.get_updates( ^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 327, in get_updates return _make_request(token, method_url, params=payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 167, in _make_request json_result = _check_result(method_name, result) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 194, in _check_result raise ApiTelegramException(method_name, result, result_json) telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway " 2024-05-14 01:15:10,714 (init.py:1212 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway" 2024-05-14 01:15:10,716 (init.py:1214 MainThread) ERROR - TeleBot: "Exception traceback: Traceback (most recent call last): File "/venv/lib/python3.12/site-packages/telebot/init.py", line 1205, in __threaded_polling polling_thread.raise_exceptions() File "/venv/lib/python3.12/site-packages/telebot/util.py", line 111, in raise_exceptions raise self.exception_info File "/venv/lib/python3.12/site-packages/telebot/util.py", line 93, in run task(args, **kwargs) File "/venv/lib/python3.12/site-packages/telebot/init.py", line 675, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/init__.py", line 647, in get_updates json_updates = apihelper.get_updates( ^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 327, in get_updates return _make_request(token, method_url, params=payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 167, in _make_request json_result = _check_result(method_name, result) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 194, in _check_result raise ApiTelegramException(method_name, result, result_json) telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway " 2024-05-14 01:16:16 - pyTMbot - ERROR - Connection error. Retry after 30 seconds [main.py | start_polling:44] 2024-05-14 01:16:46 - pyTMbot - INFO - Start polling [main.py | start_polling:39]

AsdertyTreds commented 4 months ago

I had no problems connecting to the Internet Perhaps the problem is in the Telebot API need exception handling

orenlab commented 4 months ago

Hi, @AsdertyTreds!

Can you please try the latest version from the main branch and let me know the outcome?

I have been testing this all day and, according to my logs, everything seems to be working fine.

The only thing to note is that I am not sure which version you currently have. I have transferred all the relevant configuration information to .pytmbotenv. If you experience any issues during startup, could you please try running setup_bot.py again?

orenlab commented 4 months ago

Well, I have added a custom exception handler. Let's focus on the branch 26-error-telebot-threaded-polling-exception

AsdertyTreds commented 4 months ago

thank you for your desire to improve this project.

I updated to 26

orenlab commented 4 months ago

@AsdertyTreds

I will be making some additions to branch 26 and am currently testing this solution, which is recommended by the developers of PyTelegramBotAPI for exception handling.

I will let you know about my decision.

AsdertyTreds commented 4 months ago

2024-05-16 01:10:59,244 (init.py:1221 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway" 2024-05-16 01:10:59,245 (init.py:1223 MainThread) ERROR - TeleBot: "Exception traceback: Traceback (most recent call last): File "/venv/lib/python3.12/site-packages/telebot/init.py", line 1214, in threaded_polling polling_thread.raise_exceptions() File "/venv/lib/python3.12/site-packages/telebot/util.py", line 111, in raise_exceptions raise self.exception_info File "/venv/lib/python3.12/site-packages/telebot/util.py", line 93, in run task(*args, **kwargs) File "/venv/lib/python3.12/site-packages/telebot/init.py", line 676, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/init__.py", line 648, in get_updates json_updates = apihelper.get_updates( ^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 328, in get_updates return _make_request(token, method_url, params=payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 168, in _make_request json_result = _check_result(method_name, result) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 195, in _check_result raise ApiTelegramException(method_name, result, result_json) telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway " 2024-05-16 01:10:59,623 (init.py:1221 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway" 2024-05-16 01:10:59,626 (init.py:1223 MainThread) ERROR - TeleBot: "Exception traceback: Traceback (most recent call last): File "/venv/lib/python3.12/site-packages/telebot/init.py", line 1214, in threaded_polling polling_thread.raise_exceptions() File "/venv/lib/python3.12/site-packages/telebot/util.py", line 111, in raise_exceptions raise self.exception_info File "/venv/lib/python3.12/site-packages/telebot/util.py", line 93, in run task(*args, kwargs) File "/venv/lib/python3.12/site-packages/telebot/init.py", line 676, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/init.py", line 648, in get_updates json_updates = apihelper.get_updates( ^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 328, in get_updates return _make_request(token, method_url, params=payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 168, in _make_request json_result = _check_result(method_name, result) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 195, in _check_result raise ApiTelegramException(method_name, result, result_json) telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway " 2024-05-16 01:11:00,255 (init.py:1221 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway" 2024-05-16 01:11:00,257 (init.py:1223 MainThread) ERROR - TeleBot: "Exception traceback: Traceback (most recent call last): File "/venv/lib/python3.12/site-packages/telebot/init.py", line 1214, in __threaded_polling polling_thread.raise_exceptions() File "/venv/lib/python3.12/site-packages/telebot/util.py", line 111, in raise_exceptions raise self.exception_info File "/venv/lib/python3.12/site-packages/telebot/util.py", line 93, in run task(*args, **kwargs) File "/venv/lib/python3.12/site-packages/telebot/init.py", line 676, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/init.py", line 648, in get_updates json_updates = apihelper.get_updates( ^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 328, in get_updates return _make_request(token, method_url, params=payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 168, in _make_request json_result = _check_result(method_name, result) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 195, in _check_result raise ApiTelegramException(method_name, result, result_json) telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway " 2024-05-16 01:11:01,386 (init.py:1221 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway" 2024-05-16 01:11:01,388 (init.py:1223 MainThread) ERROR - TeleBot: "Exception traceback: Traceback (most recent call last): File "/venv/lib/python3.12/site-packages/telebot/init.py", line 1214, in __threaded_polling polling_thread.raise_exceptions() File "/venv/lib/python3.12/site-packages/telebot/util.py", line 111, in raise_exceptions raise self.exception_info File "/venv/lib/python3.12/site-packages/telebot/util.py", line 93, in run task(*args, kwargs) File "/venv/lib/python3.12/site-packages/telebot/init.py", line 676, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/init__.py", line 648, in get_updates json_updates = apihelper.get_updates( ^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 328, in get_updates return _make_request(token, method_url, params=payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 168, in _make_request json_result = _check_result(method_name, result) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/telebot/apihelper.py", line 195, in _check_result raise ApiTelegramException(method_name, result, result_json) telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway " 2024-05-16 01:12:08 - pyTMbot - ERROR - Connection error. Retry after 5 seconds [main.py | start_polling:44] 2024-05-16 01:12:13 - pyTMbot - INFO - Start polling [main.py | start_polling:39]

orenlab commented 4 months ago

I confirm that there were also exceptions at night. I will consider this

orenlab commented 4 months ago

@AsdertyTreds,

Solved the problem of catching exceptions from Telebot. Updates are available in the branch 26-error-telebot-threaded-polling-exception. The tests have shown that everything is working correctly. Today, I will be transferring these changes to the development branch.

2024-05-16 05:50:44 - pyTMbot - INFO - New instance started! PyTMBot v.0.0.5 (https://github.com/orenlab/pytmbot) [main.py | run_bot:64]
2024-05-16 05:50:44 - pyTMbot - INFO - Start polling [main.py | start_polling:39]
2024-05-17 01:10:37 - pyTMbot - ERROR - A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway [__init__.py | handle:32]
2024-05-17 01:10:37 - pyTMbot - ERROR - A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway [__init__.py | handle:32]
2024-05-17 01:10:38 - pyTMbot - ERROR - A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway [__init__.py | handle:32]
2024-05-17 01:10:38 - pyTMbot - ERROR - A request to the Telegram API was unsuccessful. Error code: 502. Description: Bad Gateway [__init__.py | handle:32]
2024-05-17 01:11:43 - pyTMbot - ERROR - HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=65) [__init__.py | handle:32]
2024-05-17 06:12:51 - pyTMbot - INFO - Request from: ************, user_id **************. Accepted. [auth.py | pre_process:33]