Django MySQL:使用mysqlclient和Python 2.7的SSL错误

时间:2016-06-16 15:31:01

标签: python mysql django python-2.7 ssl


我是一个Django newby(我昨天开始)并且我正在尝试配置数据库。但是因为我认为我总是在使用Django和MySQL,所以我想设置它。我阅读了文档,我看到为了使用MySQL,你必须安装一个模块,所以我做了。我安装了mysqlclient,因为我用pip返回安装了MySQLdb:

$ pip2 install mysqldb

Could not find a version that satisfies the requirement mysqldb (from versions: )
No matching distribution found for mysqldb

并且Oracle解决方案根本不起作用(django不认识它)。 所以我输入了我的凭据,它在项目的settings.py中显示如下:

DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.sqlite3',
        # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'dbname_entered_and_tested',
        'USER': 'username_entered_and_tested',
        'PASSWORD': 'correct_password',
        'HOST': 'externale.domain_name_to_db.com',
        'PORT': '3306',

    }
}

所以它归还了我

$ python manage.py runserver

... 30 lines of Exceptions ...

django.db.utils.OperationalError: (2026, 'SSL connection error: error:00000001:lib(0):func(0):reason(1)')

所以我用谷歌搜索了Django AWS RDS MySQL Error: (2026, 'SSL connection error: error:00000001:lib(0):func(0):reason(1)')

所以我将设置设置为:

DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.sqlite3',
        # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'dbname_entered_and_tested',
        'USER': 'username_entered_and_tested',
        'PASSWORD': 'correct_password',
        'HOST': 'externale.domain_name_to_db.com',
        'PORT': '3306',
        'OPTIONS': {
            'skip-ssl',
        },
    }
}

它让我回来了

 $ python manager.py runserver

 ... 30 lines of Exceptions ...

 ValueError: dictionary update sequence element #0 has length 8; 2 is required

所以我在阅读了另一个stackoverflow帖子后,使用OpenSSL和MySQL doc(https://dev.mysql.com/doc/refman/5.6/en/creating-ssl-files-using-openssl.html)设法生成了自己的证书,并且我成功了,但是django也是这样:

 django.db.utils.OperationalError: (2026, 'SSL connection error: error:00000001:lib(0):func(0):reason(1)')

我已经尝试使用相同的凭据连接多个其他客户端到我的数据库,禁用SSL,启用SSL,另一个用户帐户。

我找到了一个解决方案,但它涉及将MySQL版本降级到5.6.27(Django server not starting correctly seems to be a mysql issue.)并且它不会成为问题...如果我只能:C。 MySQL数据库对很多Django用户来说都很痛苦(很多帖子都在谈论那个......)而且我只是一个新手,但我不想被一个简单的沮丧bug和停止Django:S

那么,有人有答案吗?

编辑:我使用的是django,pip和mysqlclient的最新版本

0 个答案:

没有答案