简体   繁体   中英

Mysql not working with python 3.6 and django 1.9

I am trying to connect mysql db with django 1.9 and python version is 3.6. With database connection string I am getting the below error. If I comment out the database connection string the site is loading fine. Can anybody tell what is wrong in this.

[Wed Apr 05 07:01:08.287609 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] mod_wsgi (pid=29791): Target WSGI script '/home/abhadran/test/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[Wed Apr 05 07:01:08.287675 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] mod_wsgi (pid=29791): Exception occurred processing WSGI script '/home/abhadran/test/mysite/mysite/wsgi.py'.
[Wed Apr 05 07:01:08.287705 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] Traceback (most recent call last):
[Wed Apr 05 07:01:08.287740 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570]   File "/home/abhadran/test/mysite/mysite/wsgi.py", line 20, in <module>
[Wed Apr 05 07:01:08.287787 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570]     application = get_wsgi_application()
[Wed Apr 05 07:01:08.287798 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570]   File "/home/abhadran/myenv/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Wed Apr 05 07:01:08.290733 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570]     django.setup(set_prefix=False)
[Wed Apr 05 07:01:08.290756 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570]   File "/home/abhadran/myenv/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
[Wed Apr 05 07:01:08.290779 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570]     apps.populate(settings.INSTALLED_APPS)
[Wed Apr 05 07:01:08.290790 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570]   File "/home/abhadran/myenv/lib/python3.6/site-packages/django/apps/registry.py", line 78, in populate
[Wed Apr 05 07:01:08.291738 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570]     raise RuntimeError("populate() isn't reentrant")
[Wed Apr 05 07:01:08.291768 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] RuntimeError: populate() isn't reentrant

My pip freeze

Django==1.9.12
django-tastypie==0.13.3
mod-wsgi==4.5.15
mysql-connector-python==2.0.4
mysqlclient==1.3.10
PyMySQL==0.6
python-dateutil==2.6.0
python-mimeparse==1.6.0
requests==2.13.0
six==1.10.0

DB Settings we are using to try to connect to the Mysql

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
    'HOST': 'AAAAAAAAAAAAAAAAA',
        'NAME': 'ZZZZZZZZZZZZZZZZ',
    'USER': 'YYYYYYYYYYYYYYYY',
        'PASSWORD': 'XXXXXXXXXXXX',
    'PORT': '3306',
        'OPTIONS': {
            'init_command': 'SET storage_engine=INNODB',
        },
    }
}

Usually, this error means there is an error in the Django project somewhere. It could be hard to locate.

You can try multiple solutions like: 1. Restart Apache 2. Execute makemigrations and migrate Django commands 3. Modify your wsgi.py file so you can manage the exception

A little note, in the line File "/home/abhadran/myenv/lib/python3.6/site-packages/django/apps/registry.py" indicate that you're using Python 3.6 and not Python 3.5 as you mentioned in your description.

Python 3.6 is officially supported until Django 1.11, so you maybe must upgrade your Django version or downgrade your Python in your venv.

Related posts: - Post 1 - Post 2 - Post 3 - Post 4 - Post 5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM