【发布时间】:2020-11-18 10:05:58
【问题描述】:
如何使用 Python 的 peewee 库连接到 MySQL 数据库,同时指定 tls-versions ['TLSv1.1', 'TLSv1.2'] 如 MySQL 文档中的 here 和 here 所示?
我可以使用 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。结果,我收到一条错误消息:
配置不当:未安装 MySQL 驱动程序!
我很确定问题在于在 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
【问题讨论】:
标签: python-3.x ssl tls1.2 peewee mysql-connector-python