使用 Python peewee 连接到 MySQL 时如何指定 tls 版本 'TLSv1.2'

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

如何在指定 tls 版本 ['TLSv1.1'、'TLSv1.2'] 时使用 Python 的 peewee 库连接到 MySQL 数据库 here and here 在 MySQL 文档中?

我可以使用 mysql.connector 成功连接到 MySQL 数据库,如下所示:

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()

但是,我无法在建立连接时将'tls_versions'参数传递给peewee。结果,我收到一条错误消息:

ImproperlyConfigured: MySQL driver not installed!

我很确定问题出在 peewee 中指定 tls 版本,因为在添加额外的 'tls_versions' 参数之前,我收到了与 mysql.connector 相同的错误消息。

这是我在 peewee 中使用的失败代码:

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

我的设置:

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

当我回复您的 github 问题时:

您需要使用 playhouse.mysql_ext.MySQLConnectorDatabase 使用 mysql 连接器驱动程序进行连接。这将解决您的问题。