mysql - 将 tls1.2 与 python 3.5 和 mysql 服务器一起使用

标签 mysql python-3.x tls1.2

我已成功从我的 python 应用程序连接到 mysql 服务器,如下 https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html

问题是我使用 tls 版本 1。 但我想至少使用 tls 1.2

在 mysql 服务器上,我设置为仅使用 tls1.1 和 1.2。 当我尝试连接到 mysql python 时提示版本错误。

mysql.connector.errors.InterfaceError: 2055: 
Lost connection to MySQL server `at '192.168.99.100:3306',`
 system error: 1 [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1045)

print(ssl.OPENSSL_VERSION) 显示 OpenSSL 1.0.2d 2015 年 7 月 9 日 我应该怎么做才能让python 3.5使用tls1.2

我使用的代码

from tkinter import *
import mysql.connector
from mysql.connector.constants import ClientFlag
from datetime import datetime
import ssl
print(ssl.OPENSSL_VERSION)
config = {
    'user': 'user',
    'password': 'password',
    'host': '192.168.99.100',
    'database' : "pizza",
    'client_flags': [ClientFlag.SSL],
    'ssl_ca': 'C:\\Users\\Linux\\PycharmProjects\\Kassa\\ca-cert.pem',
    'ssl_cert':'C:\\Users\\Linux\\PycharmProjects\\Kassa\\client-cert.pem',
    'ssl_key':'C:\\Users\\Linux\\PycharmProjects\\Kassa\\client-key.pem'
}
mydb = mysql.connector.connect(**config)
mycursor = mydb.cursor()

最佳答案

在浪费了很多时间之后,我终于找到了问题所在。 问题很简单。 我使用 pycharm 并下载了错误的 sql-connector,它只支持 tls1。 通过从 mysql 网站获取 mysql-connector-python,我得到了正确的版本 8.0.12

所以为了将来,检查一下你使用的更好的软件的所有版本。

关于mysql - 将 tls1.2 与 python 3.5 和 mysql 服务器一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52515869/

相关文章:

sql - Mysql DateTime 组按 15 分钟

python - 为什么在 Python 3.x 中的循环中使用 list() 会返回内存错误?

python - Pandas 结合两个数据框将列的子集附加到输出表的行

python - 如何修复 Windows 10 上 Python 3 中的 notification2 'dbus' 错误

ssl - crypt-protocol 值为 '-' 的 IIS 日志表示什么?

ssl - OpenLDAP - 为 LDAP TLS 连接启用 CRL 检查

android - Pjsua2.so 支持 tls,无法加载到 android 项目

php - PDO 调用在 PHP 中失败,但在 MySQL Workbench 中成功执行

php - 基于连接查询记录未返回预期结果

mysql - 我想使用 SELECT 对表中的某些字段执行 UPDATE