Forums

SSL error: decryption failed or bad record

Hey, so I've been trying to get my website up and running on here. It works; however, I get this SQL error after a few executes, and then the whole connection to the database disconnects - resulting in a fail.

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/home/LeDiamant/mysite/app.py", line 107, in dashboard cursor.execute("SELECT value FROM level_settings WHERE guild = %s AND type = %s", (str(guild_id), "Level Disabled",)) psycopg2.OperationalError: SSL error: decryption failed or bad record mac

How would I fix this? I don't get this error anywhere else, running locally is fine. I make the connection to the database when the web app is started - I'm not sure if this is the way to do it or make a connection per user that goes onto the website.

Would it be a database issue (like Firewall) or a web app issue?

Are you creating the database connection at module level -- that is, outside of your view functions? If so, that would explain the problem. When a website is started, the system initially imports all of your code, then it forks off multiple subprocesses to run it. If you're creating a database connection at module level, it will be created prior to the fork, so all of the subprocesses will be trying to use the same connection and tripping over each other.

The best solution is to use something like Flask-SQLAlchemy to manage your database connections -- it will abstract all of that away so that you don't need to worry about it.

A second-best solution is to create a fresh connection at the start of each view function that uses the database (and to close it at the end, of course).

Ahhh okay, that makes sense! I shall try that, thank you!

Great! Let us know if you hit any further problems.