Python MySQL 连接器:无法使用 SSL 连接到服务器 [英] Python MySQL Connector: Can't connect to server with SSL

查看:56
本文介绍了Python MySQL 连接器:无法使用 SSL 连接到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到安全的 MySQL 实例.我可以使用其他工具(包括 MySQL Workbench 和 MySQL Shell)中的 SSL 从这台机器连接到这台服务器.

I'm trying to connect to a secured MySQL instance. I can connect to this server from this machine using SSL from other tools, including MySQL Workbench and MySQL Shell.

但是,当我使用默认连接参数进行连接时:

However, when I connect using the default connection arguments:

currdb = mysql.connector.connect(
    host="hostname",
    user="user",
    password="hunter2",
    port=3306 )

知道我的服务器配置了

require_secure_transport = 1

我收到服务器错误:

mysql.connector.errors.DatabaseError: 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.

根据 MySQL 连接器文档,连接器应首先尝试 SSL 连接,然后回退到不安全的连接.很明显,SSL 连接失败了,没有任何解释.

Per the MySQL Connector documentation, the connector should attempt an SSL connection first, then fall back to an insecure connection. So evidently the SSL connection is failing with no explanation.

当我知道 SSL 连接可用于同一台机器上的其他工具时,如何解决失败的 SSL 连接?

How do I troubleshoot the failed SSL connection when I know it's working for other tools on the same machine?

Python 版本:3.7.2

MySQL 服务器版本:5.7.30

MySQL Server version: 5.7.30

MySQL 连接器版本:2.2.9

MySQL Connector version: 2.2.9

推荐答案

我认为您需要提供以下标志:

I think you need to provide these flags:

ssl_ca 包含 SSL 证书颁发机构的文件.

ssl_ca File containing the SSL certificate authority.

ssl_cert 包含 SSL 证书文件的文件.

ssl_cert File containing the SSL certificate file.

ssl_key 包含 SSL 密钥的文件.

ssl_key File containing the SSL key.

这篇关于Python MySQL 连接器:无法使用 SSL 连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆