我正在try 使用db_url通过flask应用程序中的一些安全选项连接到远程mysql(MariaDB)数据库.简化测试版本:

from sqlalchemy import create_engine
engine = create_engine(
    'mysql+mysqlconnector://user:password@remote.host.com:3306/mydb?'+
    'ssl_key=/path/to/key.pem'+
    '&ssl_cert=/path/to/scrt.crt'
)
connection = engine.connect()

并获取导致SSL问题的错误

sqlalchemy.exc.InterfaceError: (mysql.connector.errors.InterfaceError) 2026 (HY000): SSL connection error: error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol
(Background on this error at: http://sqlalche.me/e/rvf5)

(我还try 了pymysql而不是mysqlconnector)

HOWEVER (what I don't understand)

mysql -u user -ppassword mydb -h remote.host.com --ssl-cert=/path/to/scrt.crt --ssl-key=/path/to/key.pem

以防万一:

> SHOW VARIABLES LIKE "%version%";

+-----------------------------------+------------------------------------------+
| Variable_name                     | Value                                    |
+-----------------------------------+------------------------------------------+
| in_predicate_conversion_threshold | 1000                                     |
| innodb_version                    | 10.3.34                                  |
| protocol_version                  | 10                                       |
| slave_type_conversions            |                                          |
| system_versioning_alter_history   | ERROR                                    |
| system_versioning_asof            | DEFAULT                                  |
| version                           | 10.3.34-MariaDB-0ubuntu0.20.04.1         |
| version_comment                   | Ubuntu 20.04                             |
| version_compile_machine           | x86_64                                   |
| version_compile_os                | debian-linux-gnu                         |
| version_malloc_library            | system                                   |
| version_source_revision           | a36fc80aeb3f835fad02f443d65dc608b74b92d1 |
| version_ssl_library               | YaSSL 2.4.4                              |
| wsrep_patch_version               | wsrep_25.24                              |
+-----------------------------------+------------------------------------------+

以防万一2.同样在openssl配置/etc/ssl/openssl.cnf中(服务器1,而不是remote.host.com)

...
[system_default_sect]
MinProtocol = TLSv1.1
...

注意:我最近将服务器更新为Ubuntu 20.04.4 LTS,将python更新为3.8.10(可能与此无关)

推荐答案

经过大量挖掘,问题最终变成了过时的远程数据库版本.升级后,一切正常.

我的理解是,在数据库上使用的TLS版本太不安全(在%version%个变量中不存在).升级后,我得到了以下结果:

tls_version    | TLSv1.1,TLSv1.2,TLSv1.3 

与客户端(MinProtocol = TLSv1.1)上openssl要求的版本兼容

Python相关问答推荐

剧作家Python没有得到回应

Chatgpt API不断返回错误:404未能从API获取响应

如何在图片中找到这个化学测试条?OpenCV精明边缘检测不会绘制边界框

Pydantic 2.7.0模型接受字符串日期时间或无

使用FASTCGI在IIS上运行Django频道

Matlab中是否有Python的f-字符串等效物

处理(潜在)不断增长的任务队列的并行/并行方法

Python中绕y轴曲线的旋转

基于索引值的Pandas DataFrame条件填充

提取相关行的最快方法—pandas

使用Python从URL下载Excel文件

基于形状而非距离的两个numpy数组相似性

如何检测鼠标/键盘的空闲时间,而不是其他输入设备?

为什么在FastAPI中创建与数据库的连接时需要使用生成器?

PYTHON、VLC、RTSP.屏幕截图不起作用

BeautifulSoup-Screper有时运行得很好,很健壮--但有时它失败了::可能这里需要一些更多的异常处理?

每次查询的流通股数量

浏览超过10k页获取数据,解析:欧洲搜索服务:从欧盟站点收集机会的微小刮刀&

启动线程时,Python键盘模块冻结/不工作

如何在python tkinter中绑定键盘上的另一个回车?