Python SQL连接错误(2006,"SSL连接错误:SSL_CTX_set_tmp_dh失败") [英] Python SQL connection error (2006, 'SSL connection error: SSL_CTX_set_tmp_dh failed')
问题描述
我曾经以这种方式连接到我的AWS-RDS实例
I used to connect to my AWS-RDS instance this way
import MySQLdb
db = MySQLdb.connect(host=os.getenv('RDS_ENDPOINT'),
user=os.getenv('RDS_USER'),
passwd=os.getenv('RDS_PWD'),
db=os.getenv('RDS_DB'))
或借助sqlalchemy,但今天似乎拒绝处理错误(2006, 'SSL connection error: SSL_CTX_set_tmp_dh failed')
or with the help of sqlalchemy, but today it seem to refuse to work with the error (2006, 'SSL connection error: SSL_CTX_set_tmp_dh failed')
我尝试更新所有python软件包(mysqlclient
,sqlalchemy
),重新安装mysqlclient-dev
,手动重新安装OpenSSL v1.1.1a
,但仍然是相同的错误.
I tried to update all the python packages (mysqlclient
, sqlalchemy
), reinstall mysqlclient-dev
, manually reinstall OpenSSL v1.1.1a
but still the same error.
我设法使用MySQL CLI连接到同一数据库
I manage to connect to the same database using the MySQL CLI
mysql --user=$RDS_USER --host=$RDS_ENDPOINT --password=$RDS_PWD $RDS_DB
[解决方案]
这似乎是驱动程序问题.我尝试对Python 3使用mysqlclient
并收到此错误.接下来,我尝试按要求使用mysql.connector
,但是遇到了编码问题(如sqlalchemy文档中所述).最后,我以pymysql
驱动程序结束,该驱动程序似乎可以与sqlalchemy一起使用.
It seems that this is a driver issue. I tried with mysqlclient
for python 3 and got this error. Next I tried with mysql.connector
as recommanded but I got encoding issues (as stated in the sqlalchemy doc). Finally, I ended with the pymysql
driver which seems to work with sqlalchemy.
推荐答案
升级mysqlclient软件包解决了该问题.
Upgrade mysqlclient package fixed the problem.
这篇关于Python SQL连接错误(2006,"SSL连接错误:SSL_CTX_set_tmp_dh失败")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!