@RuslanShams

Со временем появляется ошибка TelegramAPIError: Bad Gateway как поправить?

Это код в котором появляется ошибка
...
logging.info("downloading the file from url " + url)
with ydl:#GOOGLE
 result = ydl.extract_info(
url,
download = True
 )
logging.info("the file from " + url + " downloaded").
...


Вот логи

INFO:root:downloading the file from url https://www.youtube.com/watch?v=A-wArtkftDI
ERROR:asyncio:Task exception was never retrieved
future: exception=OSError(5, 'Input/output error')>
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 1976, in process_info
success = dl(filename, info_dict)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 1915, in dl
return fd.download(name, info)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/downloader/common.py", line 366, in download
return self.real_download(filename, info_dict)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/downloader/http.py", line 352, in real_download
return download()
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/downloader/http.py", line 301, in download
self._hook_progress({
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/downloader/common.py", line 374, in _hook_progress
ph(status)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/downloader/common.py", line 306, in report_progress
self._report_progress_status(msg_template % s)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/downloader/common.py", line 245, in _report_progress_status
self.to_screen(clear_line + fullmsg, skip_eol=not is_last_line)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/downloader/common.py", line 150, in to_screen
self.ydl.to_screen(*args, **kargs)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 506, in to_screen
return self.to_stdout(message, skip_eol, check_quiet=True)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 520, in to_stdout
self._write_string(output, self._screen_file)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 509, in _write_string
write_string(s, out=out, encoding=self.params.get('encoding'))
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/utils.py", line 3232, in write_string
out.flush()
OSError: [Errno 5] Input/output error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "/usr/MyRobot/tel.py", line 135, in echo_message
result = ydl.extract_info(
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 808, in extract_info
return self.__extract_info(url, ie, download, extra_info, process)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 815, in wrapper
return func(self, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 847, in __extract_info
return self.process_ie_result(ie_result, download, extra_info)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 881, in process_ie_result
return self.process_video_result(ie_result, download=download)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 1692, in process_video_result
self.process_info(new_info)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 1978, in process_info
self.report_error('unable to download video data: %s' % error_to_compat_str(err))
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 628, in report_error
self.trouble(error_message, tb)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 581, in trouble
self.to_stderr(message)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 530, in to_stderr
self._write_string(output, self._err_file)
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/YoutubeDL.py", line 509, in _write_string
write_string(s, out=out, encoding=self.params.get('encoding'))
File "/usr/local/lib/python3.10/dist-packages/youtube_dl/utils.py", line 3232, in write_string
out.flush()
OSError: [Errno 5] Input/output error
ERROR:aiogram.dispatcher.dispatcher:Cause exception while getting updates.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 381, in start_polling
updates = await self.bot.get_updates(
File "/usr/local/lib/python3.10/dist-packages/aiogram/bot/bot.py", line 110, in get_updates
result = await self.request(api.Methods.GET_UPDATES, payload)
File "/usr/local/lib/python3.10/dist-packages/aiogram/bot/base.py", line 236, in request
return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
File "/usr/local/lib/python3.10/dist-packages/aiogram/bot/api.py", line 139, in make_request
async with session.post(url, data=req, **kwargs) as response:
File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 1141, in __aenter__
self._resp = await self._coro
File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 467, in _request
with timer:
File "/usr/local/lib/python3.10/dist-packages/aiohttp/helpers.py", line 720, in __exit__
raise asyncio.TimeoutError from None
asyncio.exceptions.TimeoutError
ERROR:aiogram.dispatcher.dispatcher:Cause exception while getting updates.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 381, in start_polling
updates = await self.bot.get_updates(
File "/usr/local/lib/python3.10/dist-packages/aiogram/bot/bot.py", line 110, in get_updates
result = await self.request(api.Methods.GET_UPDATES, payload)
File "/usr/local/lib/python3.10/dist-packages/aiogram/bot/base.py", line 236, in request
return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
File "/usr/local/lib/python3.10/dist-packages/aiogram/bot/api.py", line 140, in make_request
return check_result(method, response.content_type, response.status, await response.text())
File "/usr/local/lib/python3.10/dist-packages/aiogram/bot/api.py", line 128, in check_result
raise exceptions.TelegramAPIError(description)
aiogram.utils.exceptions.TelegramAPIError: Bad Gateway


Здесь aiogram.utils.exceptions.TelegramAPIError: Bad Gateway появляется после какого-то времени буд-то сервер работает все норм, но спустя какое-то время перестает сервер отвечать на запросы и крашится с 502 ошибкой, гуглил везде где можно, какого-то сольюшена нет адекватного, подскажите пожалуйста как можно это поправить - может повторно воткнуть start_polling
bot = Bot(token=TOKEN)
dp = Dispatcher(bot)
<b>executor.start_polling(dp)</b>

?
  • Вопрос задан
  • 1063 просмотра
Пригласить эксперта
Ответы на вопрос 1
Carnage
@Carnage
QA Automation, DevOps, Java, Python
Ошибка появляется не со временем, а когда вы пытаетесь загрузить видео через библиотеку ютуб даунлодера. Неплохо бы добавить туда обработку эксепшена. К тому же та библиотека скорее всего не асинхронная. И поэтому она блокирует поток aiogram. Нужно скорее всего поискать асинхронный ютуб даунлодер или вместо аиограм использовать синхронную библиотеку.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы