What happens if you create a plain WSGI hello world without Django which
contains at the start of the WSGI script file:
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
In other words, strip away all the Django stuff and just try and import those
types from psycopg2 directly yourself.
Graham
> On 11 Feb 2016, at 1:39 PM, kwatog <[email protected]> wrote:
>
> somehow, mod_wsgi cannot load psycopg2.
>
> environment details:
> Python 3.5.1
> Django 1.9
> Apache 2.4
> CentOS 6.7
>
> Take note that everything is fine if I use manage.py runserver. Also, no
> issues with mod_wsgi + sqlite. I can choose not to use postgresql, though.
> But I'm putting up here for discussion. thanks a lot!
>
>
>
> [pid 2166] mod_wsgi (pid=2166): Attach interpreter ''.
> [pid 2166] mod_wsgi (pid=2166): Adding '/home/mkt/src' to path.
> [pid 2166] mod_wsgi (pid=2166): Adding
> '/home/mkt/mktve/lib/python3.5/site-packages' to path.
> [pid 2166] mod_wsgi (pid=2166): Imported 'mod_wsgi'.
> mod_wsgi (pid=2166, process='kwatog.com', application=''): Loading WSGI
> script '/home/mkt/src/market/wsgi.py'.
> mod_wsgi (pid=2166): Target WSGI script '/home/mkt/src/market/wsgi.py'
> cannot be loaded as Python module.
> mod_wsgi (pid=2166): Exception occurred processing WSGI script
> '/home/mkt/src/market/wsgi.py'.
> Traceback (most recent call last):
> File
> "/home/mkt/mktve/lib/python3.5/site-packages/django/db/backends/postgresql/base.py",
> line 20, in <module>
> import psycopg2 as Database
> File "/home/mkt/mktve/lib/python3.5/site-packages/psycopg2/__init__.py",
> line 50, in <module>
> from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
> ImportError: datetime initialization failed
>
>
> During handling of the above exception, another exception occurred:
>
>
> Traceback (most recent call last):
> File "/home/mkt/src/market/wsgi.py", line 17, in <module>
> application = get_wsgi_application()
> File "/home/mkt/mktve/lib/python3.5/site-packages/django/core/wsgi.py",
> line 13, in get_wsgi_application
> django.setup()
> File "/home/mkt/mktve/lib/python3.5/site-packages/django/__init__.py",
> line 18, in setup
> apps.populate(settings.INSTALLED_APPS)
> File
> "/home/mkt/mktve/lib/python3.5/site-packages/django/apps/registry.py", line
> 108, in populate
> app_config.import_models(all_models)
> File "/home/mkt/mktve/lib/python3.5/site-packages/django/apps/config.py",
> line 202, in import_models
> self.models_module = import_module(models_module_name)
> File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in
> import_module
> return _bootstrap._gcd_import(name[level:], package, level)
> File "<frozen importlib._bootstrap>", line 986, in _gcd_import
> File "<frozen importlib._bootstrap>", line 969, in _find_and_load
> File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
> File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
> File "<frozen importlib._bootstrap_external>", line 662, in exec_module
> File "<frozen importlib._bootstrap>", line 222, in
> _call_with_frames_removed
> File
> "/home/mkt/mktve/lib/python3.5/site-packages/django/contrib/auth/models.py",
> line 4, in <module>
> from django.contrib.auth.base_user import AbstractBaseUser,
> BaseUserManager
> File
> "/home/mkt/mktve/lib/python3.5/site-packages/django/contrib/auth/base_user.py",
> line 49, in <module>
> class AbstractBaseUser(models.Model):
> File
> "/home/mkt/mktve/lib/python3.5/site-packages/django/db/models/base.py", line
> 108, in __new__
> new_class.add_to_class('_meta', Options(meta, app_label))
> File
> "/home/mkt/mktve/lib/python3.5/site-packages/django/db/models/base.py", line
> 299, in add_to_class
> value.contribute_to_class(cls, name)
> File
> "/home/mkt/mktve/lib/python3.5/site-packages/django/db/models/options.py",
> line 263, in contribute_to_class
> self.db_table = truncate_name(self.db_table,
> connection.ops.max_name_length())
> File "/home/mkt/mktve/lib/python3.5/site-packages/django/db/__init__.py",
> line 36, in __getattr__
> return getattr(connections[DEFAULT_DB_ALIAS], item)
> File "/home/mkt/mktve/lib/python3.5/site-packages/django/db/utils.py",
> line 212, in __getitem__
> backend = load_backend(db['ENGINE'])
> File "/home/mkt/mktve/lib/python3.5/site-packages/django/db/utils.py",
> line 116, in load_backend
> return import_module('%s.base' % backend_name)
> File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in
> import_module
> return _bootstrap._gcd_import(name[level:], package, level)
> File
> "/home/mkt/mktve/lib/python3.5/site-packages/django/db/backends/postgresql/base.py",
> line 24, in <module>
> raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
> django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module:
> datetime initialization failed
> mod_wsgi (pid=2166, process='kwatog.com', application=''): Loading WSGI
> script '/home/mkt/src/market/wsgi.py'.
> mod_wsgi (pid=2166): Target WSGI script '/home/mkt/src/market/wsgi.py'
> cannot be loaded as Python module.
> mod_wsgi (pid=2166): Exception occurred processing WSGI script
> '/home/mkt/src/market/wsgi.py'.
> Traceback (most recent call last):
> File "/home/mkt/src/market/wsgi.py", line 17, in <module>
> application = get_wsgi_application()
> File "/home/mkt/mktve/lib/python3.5/site-packages/django/core/wsgi.py",
> line 13, in get_wsgi_application
> django.setup()
> File "/home/mkt/mktve/lib/python3.5/site-packages/django/__init__.py", line
> 18, in setup
> apps.populate(settings.INSTALLED_APPS)
> File "/home/mkt/mktve/lib/python3.5/site-packages/django/apps/registry.py",
> line 78, in populate
> raise RuntimeError("populate() isn't reentrant")
> RuntimeError: populate() isn't reentrant
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/modwsgi
> <https://groups.google.com/group/modwsgi>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.