Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python SQL connection error (2006, 'SSL connection error: SSL_CTX_set_tmp_dh failed')

Tags:

python

mysql

ssl

I used to connect to my AWS-RDS instance this way

import MySQLdb

db = MySQLdb.connect(host=os.getenv('RDS_ENDPOINT'),
                     user=os.getenv('RDS_USER'),
                     passwd=os.getenv('RDS_PWD'),
                     db=os.getenv('RDS_DB'))

or with the help of sqlalchemy, but today it seem to refuse to work with the error (2006, 'SSL connection error: SSL_CTX_set_tmp_dh failed')

I tried to update all the python packages (mysqlclient, sqlalchemy), reinstall mysqlclient-dev, manually reinstall OpenSSL v1.1.1a but still the same error.

[EDIT]

I manage to connect to the same database using the MySQL CLI

mysql --user=$RDS_USER --host=$RDS_ENDPOINT --password=$RDS_PWD $RDS_DB

[SOLUTION]

It seems that this is a driver issue. I tried with mysqlclient for python 3 and got this error. Next I tried with mysql.connector as recommanded but I got encoding issues (as stated in the sqlalchemy doc). Finally, I ended with the pymysql driver which seems to work with sqlalchemy.

like image 497
GuillaumeA Avatar asked Dec 17 '18 16:12

GuillaumeA


1 Answers

Upgrade mysqlclient package fixed the problem.

like image 84
alireza heidari Avatar answered Oct 18 '22 20:10

alireza heidari