Search code examples
python-3.xssltls1.2peeweemysql-connector-python

How to specify tls version 'TLSv1.2' when connecting to MySQL using Python peewee


How do I connect to a MySQL database using Python's peewee library while specifying the tls-versions ['TLSv1.1', 'TLSv1.2'] as shown here and here in the MySQL documentation?

I can successfully connect to the MySQL database using mysql.connector as shown here:

import mysql.connector

config = {'database': 'dbname',
 'user': 'username_so',
 'password': 'psswrd',
 'host': 'maria####-##-###-##.###.####.com',
 'port': 3306,
 'tls_versions': ['TLSv1.1', 'TLSv1.2']}

cnx = mysql.connector.connect(**config)

cnx.close()

However, I am unable to pass the 'tls_versions' parameter to peewee when establishing a connection. As a result, I get an error message:

ImproperlyConfigured: MySQL driver not installed!

I am pretty sure that the problem is with specifying the tls versions in peewee because I was getting the same error message with mysql.connector before I added in the additional 'tls_versions' parameter.

Here is the code I am using in peewee that is failing:

db = MySQLDatabase(**config)
db.get_tables() # This function and any other that connects to the db gets the same error message specified above

My Setup:

Linux
Python 3.7
peewee==3.13.3
mysql-connector-python==8.0.21

Solution

  • As I responded to your github issue:

    You need to use playhouse.mysql_ext.MySQLConnectorDatabase to connect using the mysql-connector driver. That will resolve your issue.