Forums

Aiogram Flask - Fatal error on SSL transport

I have aiogram telegram bot on webhook. Bot is working, but on error log I often see this error:

2023-02-10 22:20:36,627: Fatal error on SSL transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x7f016cbe39a0>
transport: <_SelectorSocketTransport closing fd=26>
Traceback (most recent call last):
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 916, in write n = self._sock.send(data)
OSError: [Errno 9] Bad file descriptor
**NO MATCH**
During handling of the above exception, another exception occurred:
**NO MATCH**
Traceback (most recent call last):
File "/usr/local/lib/python3.9/asyncio/sslproto.py", line 690, in _process_write_backlog
  self._transport.write(chunk)
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 922, in write
  self._fatal_error(exc, 'Fatal write error on socket transport')
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 717, in _fatal_error
   self._force_close(exc)
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 729, in _force_close
   self._loop.call_soon(self._call_connection_lost, exc)
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 751, in call_soon
   self._check_closed()
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 515, in _check_closed
   raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Info:

  • Web app - Flask
  • Python - 3.9
  • aiogram 2.x
  • domain - default domain from pythonanywhere

It happens when I receive new POST(not always) from telegram to my webhook

Is somebody know the reason and how to fix it?

We don't support threads in website code on PythonAnywhere right now, so if you're trying to spin off an async event loop, it will probably fail. You'll need to use synchronous code if you want it to work.