Using mysql-connector-python in a flask app with uwsgi and receive the following error: SSL connection error: SSL_CTX_new failed

Using mysql-connector-python in a flask app with uwsgi and receive the following error: SSL connection error: SSL_CTX_new failed

我有一个 flask 应用程序,它使用 mysql 连接,我在开发模式下已成功 运行。为了扩展应用程序,我打算结合使用 Nginx 和 uwsgi。

已设置 wsgi.py 文件和 运行 命令:

uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:app

我在输入 url 后收到以下错误消息(之前在开发模式下工作,即在没有 uwsgi 的情况下单独使用 flask):

mysql.connector.errors.InterfaceError: 2026 (HY000): SSL connection error: SSL_CTX_new failed

我已经尝试过这里建议的解决方案: https://forums.mysql.com/read.php?50,671354,671376#msg-671376 然而它没有用。

我应该怎么做才能解决这个错误?

我找到了适合我的解决方案。

添加

use_pure=True

到数据库连接字符串的末尾

所以我的变成了

connection_string = f'{dialect}+{driver}://{user}:{password}@{host}:{port}/{database}?use_pure=True'