1

Attempting to connect to RDS MySQL instance through databases dict in settings.py file yields django.db.utils.OperationalError: (2026, 'SSL connection error: SSL_CTX_set_tmp_dh failed').

The error code is similar to django.db.utils.OperationalError: (2026, 'SSL connection error: SSL_CTX_set_tmp_dh failed'), so I tried using bin/mysql_ssl_rsa_setup to create default SSL and RSA files.

Setup (Similar to SSL connection error when connecting to RDS MySQL from Django)

  • Standard Django application
  • MySQL RDS instance with security group allowing connections from all IP addresses
  • MySQL user is setup to allow connections from any host
  • Amazon's pem has been downloaded and is specified in Django settings

Connection through cli works, as does connecting in interpreter through PyMySql.

The successful PyMySql connection and query look like this:

db = pymysql.connect(user=os.environ['DEV_DATABASE_USERNAME'],
                         password=os.environ['DEV_MYSQL_PASSWORD'],
                         host=os.environ['DEV_DATABASE_HOST'],
                         cursorclass=pymysql.cursors.DictCursor, 
                         database='dev'),
                         ssl={'ssl':{'ca':<PATH TO CA CERT>}})

I've tried verifying that the path to the ca is absolute, which it is, and making sure that I'm not using python to attempt to build it, as in SSL connection error when connecting to RDS MySQL from Django.

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'dev',
    'USER': os.environ['DEV_DATABASE_USERNAME'],
    'HOST': os.environ['DEV_DATABASE_HOST'],
    'PASSWORD': os.environ['DEV_MYSQL_PASSWORD'],
    'OPTIONS':  {
        'ssl': { 'ca': <PATH TO CA CERT> },
    }
}

}

2

1 Answer 1

1

I solved this by creating an entirely new Django project with the exact same settings.py file and updating all packages in requirements.txt, so the issue was likely some incompatibility between mysqlclient, PyMySQL, and MySQL 5.6.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.