GuillaumeA
GuillaumeA

Reputation: 3545

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

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.

Upvotes: 7

Views: 4470

Answers (1)

alireza heidari
alireza heidari

Reputation: 21

Upgrade mysqlclient package fixed the problem.

Upvotes: 2

Related Questions