app.py: closing connection when it does not fails