I execute a loop in Python that queries data one after the other from the web and writes it to an sql database using a predefined function (using a SSH tunnel and cursor.execute). Both locally and in a scheduled task, the "Lost Connection to Server" error occurs at some point (it is completely random at what step the error occurs). Locally with System Error 0, on Pythonanywhere with System Error 11. Since the first X times the connection is successfully established and data is successfully written to the database, it cannot be an authentication problem from my point of view. Is there anything else that could provoke that error, for example some sort of rate limits?
I also know that it is not the best practice to disconnect and reconnect again and again and I also know that one doesn't actually need a SSH tunnel if code is executed on PythonAnywhere. Nevertheless, I would like to keep it that way for simplicity reasons if at all possible.