Python-socketio: how to handle on_error_default in python-socketio

Created on 21 Feb 2019  路  3Comments  路  Source: miguelgrinberg/python-socketio

In flask-socketio, I found the following sample code:

@socketio.on_error_default
def error_handler(e):
print('An error has occurred: ' + str(e))

How to catch the same/similar error in python-socketio please?

question

All 3 comments

You have to catch your errors yourself, using a try/except block.

@miguelgrinberg Can you explain how to handle that exceptions, thanks.
i have 2000 clients and some times i received in logs that Unhandled exception

[ 2019-03-24 17:24:54,291 ] [ ERROR ] Unhandled exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/web_protocol.py", line 447, in start
    await resp.prepare(request)
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/web_response.py", line 353, in prepare
    return await self._start(request)
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/web_response.py", line 667, in _start
    return await super()._start(request)
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/web_response.py", line 410, in _start
    await writer.write_headers(status_line, headers)
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/http_writer.py", line 112, in write_headers
    self._write(buf)
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/http_writer.py", line 67, in _write
    raise ConnectionResetError('Cannot write to closing transport')
ConnectionResetError: Cannot write to closing transport

That is an error triggered by aiohttp, so it's not something your application can control. If they don't provide a way to suppress or handle these errors, then I think you'll have to tolerate/ignore them.

Was this page helpful?
0 / 5 - 0 ratings