Issue
So I have an EC2 (ubuntu) instance on AWS running a Flask app and a mysql server.
I have a domain registered and I requested ssl certs from Let's Encrypt certbot. The problem is that when I try to access the website from my own browser (up to date chrome on win10 and up to date chrome recent android) I get an internal server error. Btw I use gunicorn and nginx. I checked the error.log file and this is what I found:
2023/12/27 02:29:45 [crit] 1360#1360: *786 SSL_do_handshake() failed (SSL: error:0A00006C:SSL routines::bad key share) while SSL handshaking, client: [my own ipv4 address], server: 0.0.0.0:443
2023/12/27 03:15:31 [crit] 1360#1360: *808 SSL_do_handshake() failed (SSL: error:0A00006C:SSL routines::bad key share) while SSL handshaking, client: 212.102.40.218, server: 0.0.0.0:443
I have ports 443 open for https and 80 for http. The firewall is active and the necessary ports are open (idk if these are relevant).
So if I do a sudo reboot this problem goes away for about 1-3 hours. I have seen other questions like this, but those only mention other clients with outdated stuff, which is not true for me.
Thanks for any advice in advance!
Solution
I found the solution. You have to open and close a new connection for every database query. Example:
import pymysql
db_config = {
'host': 'your_host',
'user': 'your_username',
'password': 'your_password',
'database': 'your_database',
'port': 3306
}
with pymysql.connect(**db_config) as connection:
with connection.cursor() as cursor:
sql = 'SELECT * FROM table;'
cursor.execute(sql)
res = cursor.fetchall()
Answered By - Daniel Answer Checked By - Gilberto Lyons (WPSolving Admin)