【问题标题】:How to specify tls version 'TLSv1.2' when connecting to MySQL using Python peewee使用 Python peewee 连接到 MySQL 时如何指定 tls 版本“TLSv1.2”
【发布时间】:2020-11-18 10:05:58
【问题描述】:

如何使用 Python 的 peewee 库连接到 MySQL 数据库,同时指定 tls-versions ['TLSv1.1', 'TLSv1.2'] 如 MySQL 文档中的 herehere 所示?

我可以使用 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


    【解决方案1】:

    当我回复你的 github 问题时:

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

    【讨论】:

      猜你喜欢
      • 2015-02-18
      • 2017-05-20
      • 2020-04-05
      • 1970-01-01
      • 2014-06-12
      • 2023-03-13
      • 2016-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多