从Django连接到RDS MySQL时发生SSL连接错误 [英] SSL connection error when connecting to RDS MySQL from Django

查看:421
本文介绍了从Django连接到RDS MySQL时发生SSL连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Heroku上部署一个具有RDS实例的Django应用程序作为数据库后端。一切正常,直到我尝试加密连接,然后我收到这个错误:

I'm trying to deploy a Django app on Heroku with an RDS instance as the database backend. Everything is working until I try to encrypt the connection, then I get this error:

OperationalError at /path/
(2026, 'SSL connection error')

这是设置:


  • 标准Django应用程序

  • 具有安全组的MySQL RDS实例允许从所有IP地址进行连接

  • MySQL用户设置为允许来自任何主机的连接

  • Amazon的pem已经下载并在Django设置中指定

  • Standard Django application
  • MySQL RDS instance with security group allowing connections from all IP addresses
  • MySQL user is setup to allow connections from any host
  • Amazon's pem has been downloaded and is specified in Django settings

在Heroku上:

DATABASE_URL: mysql2://username:password@instance.us-east-1.rds.amazonaws.com:3306/name_staging?sslca=path/to/mysql-ssl-ca-cert.pem

在Django设置中:

In Django settings:

DATABASES = {
    'default': dj_database_url.config()
}
DATABASES['default']['OPTIONS'] = {'ssl': {'ca': 'mysql-ssl-ca-cert.pem'}}`

我已经尝试搜索并且已经阅读了很多关于在Rails中设置这种类型的环境,但是有关使用Django进行此操作的文档是

I've tried searching and have read a lot about setting this type of environment up in Rails, but the documentation about doing this with Django is light to non-existent.

有没有人成功部署了类似的设置,有没有人想到如何解决这个错误?

Has anyone out there successfully deployed a similar setup or does anyone have thoughts on how to solve this error?

更新:

连接通过cli工作,以及直接使用MySQLdb在python解释器。

Connecting via cli works as well as connecting directly using MySQLdb in the python interpreter.

推荐答案

解决:

pem文件的路径必须是绝对的,你不能使用python尝试构建绝对路径。

The path to the pem file has to be absolute and you can't use python to attempt to build the absolute path.

DATABASES = {
    'default': dj_database_url.config()
}
DATABASES['default']['OPTIONS'] = {
    'ssl': {'ca': '/app/project_name/rds/mysql-ssl-ca-cert.pem'}
}

同样,检测这样的路径不起作用,路径必须哈日d编码:

Again, detecting the path like this does not work, the path must be hard coded:

DATABASES['default']['OPTIONS'] = {
    'ssl': {'ca': os.path.join(os.path.dirname(__file__), 'rds', 'mysql-ssl-ca-cert.pem')}
}

这篇关于从Django连接到RDS MySQL时发生SSL连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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