Django 500内部服务器错误 - 不正确的配置:加载MySQLdb模块时出错: [英] Django 500 Internal Server Error - ImproperlyConfigured: Error loading MySQLdb module:

查看:493
本文介绍了Django 500内部服务器错误 - 不正确的配置:加载MySQLdb模块时出错:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般来说,新的使用MySQL和Django的数据库。我遵循了许多不同的教程和文档,但是当我部署到我的生产服务器时,会继续收到<500>内部服务器错误。它在我的开发机器上工作正常。



我缺少什么?有没有一个我应该改变的设置或者我想念的一个步骤?



谢谢



错误日志

  [Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233] return getattr (connections [DEFAULT_DB_ALIAS],item)
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233] File/var/www/bias_experiment/lib/python2.7/site-packages /django/db/utils.py,第198行,__getitem__
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233] backend = load_backend(db ['ENGINE'])
[Mon Aug 18 19:23:10 2014] [错误] [客户端134.226.38.233]文件/var/www/bias_experiment/lib/python2.7/site-packages/django/db/utils.py ,line 113,in load_backend
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233] return import_module('%s.base'%backend_name)
[Mon Aug 18 19:23:10 2014] [错误] [客户端134.226.38.233]文件/var/www/bias_experiment/lib/python2.7/site-packages/django/utils/importlib.py,行40,in import_module
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233] __import __(name)
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233]文件/var/www/bias_experiment/lib/python2.7/site-packages/django/db/backends/mysql/base.py,第17行,在< module>
[Mon Aug 18 19:23:10 2014] [错误] [客户端134.226.38.233] raise不正确配置(加载MySQLdb模块时出错:%s%e)
[Mon Aug 18 19:23 :10 2014] [错误] [客户端134.226.38.233]不正确配置:加载MySQLdb模块时出错:这是MySQLdb版本(1,2,5,'final',1),但_mysql是版本(1,2,3,最终',0)

我的设置




  • Ubuntu VM运行12.04.5 LTS

  • Apache / 2.2.22(Ubuntu)

  • Python 2.7.3

  • virtualenv == 1.7.1.2

  • Django == 1.6

  • MySQL - python == 1.2.3

  • mysql Ver 14.14 Distrib 5.5.38,对于debian-linux-gnu(x86_64)使用readline 6.2



我的settings.py

  DATABASES = {
'default':{
'ENGINE':'django.db.backends.mysql',
'NAME':'django_db',
'USER':'root',
'PASSWORD':'my_password',
'HOST':'127.0.0.1',
'PORT':'',
}
}

我在我的生产环境中创建了数据库

  CREATE DATABASE django_db; 
查询OK,1行受影响(0.01秒)
mysql>

然后我运行syncdb

 (bias_experiment)Macintosh-2:src user $ python manage.py syncdb 
创建表...
创建表django_admin_log
....


解决方案

此行:

 不正确的配置:加载MySQLdb模块时出错:这是MySQLdb版本(1,2,5,'final',1),但_mysql是版本(1,2,3,'final ',0)

表示您可能在MysqlDB和MySQL之间的版本不匹配。
听起来像看着它,重新安装你的依赖库解决了这个问题。



更详细地描述这个问题: / p>

在这种情况下apt-get正在安装MySQL-python == 1.2.3。最新版本是MySQL-python == 1.2.5。
但是apt-get没有找到它,所以完全删除MySQL-python == 1.2.3使用:

  sudo apt-get remove --purge python-mysqldb 

然后通过点重新安装

  sudo pip install mysql-python 

(注意包名略有不同)


Im new to using MySQL in general and as a database for Django. I have followed a number of different tutorials and the documentation but keep getting a 500 Internal Server Error when i deploy to my production server. It works fine on my development machine.

What am I missing? is there a setting I should change or a step i missed?

Thanks

The Error logs

[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233]     return getattr(connections[DEFAULT_DB_ALIAS], item)
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233]   File "/var/www/bias_experiment/lib/python2.7/site-packages/django/db/utils.py", line 198, in __getitem__
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233]     backend = load_backend(db['ENGINE'])
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233]   File "/var/www/bias_experiment/lib/python2.7/site-packages/django/db/utils.py", line 113, in load_backend
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233]     return import_module('%s.base' % backend_name)
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233]   File "/var/www/bias_experiment/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233]     __import__(name)
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233]   File "/var/www/bias_experiment/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233]     raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
[Mon Aug 18 19:23:10 2014] [error] [client 134.226.38.233] ImproperlyConfigured: Error loading MySQLdb module: this is MySQLdb version (1, 2, 5, 'final', 1), but _mysql is version (1, 2, 3, 'final', 0)

My Setup

  • Ubuntu VM running 12.04.5 LTS
  • Apache/2.2.22 (Ubuntu)
  • Python 2.7.3
  • virtualenv==1.7.1.2
  • Django==1.6
  • MySQL-python==1.2.3
  • mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (x86_64) using readline 6.2

My settings.py

DATABASES = {
    'default': { 
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'django_db',                                       
        'USER': 'root',
        'PASSWORD': 'my_password',
        'HOST': '127.0.0.1',
        'PORT': '', 
    }
}

I have created the database on my production environment

CREATE DATABASE django_db;
Query OK, 1 row affected (0.01 sec) 
mysql>

I then ran syncdb

(bias_experiment)Macintosh-2:src user$ python manage.py syncdb
Creating tables ...
Creating table django_admin_log
....

解决方案

This line:

ImproperlyConfigured: Error loading MySQLdb module: this is MySQLdb version (1, 2, 5, 'final', 1), but _mysql is version (1, 2, 3, 'final', 0) 

indicates you might have a version mismatch between MysqlDB and MySQL. Sounds like looking in to it and reinstalling your dependent libraries resolved the issue.

To describe the issue in further detail:

In this case apt-get was installing MySQL-python==1.2.3. The latest version is MySQL-python==1.2.5. However apt-get was not finding it, so completely removing MySQL-python==1.2.3 using:

sudo apt-get remove --purge python-mysqldb

and then reinstall via pip

sudo pip install mysql-python

(Note the package names are slightly different)

这篇关于Django 500内部服务器错误 - 不正确的配置:加载MySQLdb模块时出错:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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