У меня есть приложение Django, использующее RDS Postgres на AWS Beanstalk.Среда Beanstalk не использует настройку RDS по умолчанию.У меня работает отдельный экземпляр RDS Postgres.
В моем файле настроек у меня есть следующее для моего словаря базы данных:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
Когда я посещаю URL-адрес среды, я получаю ошибку 500.Ниже приведены error_logs
за одно посещение.
[Sun Dec 23 18:43:24.116897 2018] [:error] [pid 1881] [remote 172.31.30.131:0] mod_wsgi (pid=1881): Target WSGI script '/opt/python/current/app/my_app/wsgi.py' cannot be loaded as Python module.
[Sun Dec 23 18:43:24.117094 2018] [:error] [pid 1881] [remote 172.31.30.131:0] mod_wsgi (pid=1881): Exception occurred processing WSGI script '/opt/python/current/app/my_app/wsgi.py'.
[Sun Dec 23 18:43:24.117230 2018] [:error] [pid 1881] [remote 172.31.30.131:0] Traceback (most recent call last):
[Sun Dec 23 18:43:24.117313 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/current/app/my_app/wsgi.py", line 16, in <module>
[Sun Dec 23 18:43:24.117458 2018] [:error] [pid 1881] [remote 172.31.30.131:0] application = get_wsgi_application()
[Sun Dec 23 18:43:24.117553 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Sun Dec 23 18:43:24.117668 2018] [:error] [pid 1881] [remote 172.31.30.131:0] django.setup(set_prefix=False)
[Sun Dec 23 18:43:24.117757 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
[Sun Dec 23 18:43:24.117899 2018] [:error] [pid 1881] [remote 172.31.30.131:0] apps.populate(settings.INSTALLED_APPS)
[Sun Dec 23 18:43:24.117971 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
[Sun Dec 23 18:43:24.118183 2018] [:error] [pid 1881] [remote 172.31.30.131:0] app_config.import_models()
[Sun Dec 23 18:43:24.118266 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
[Sun Dec 23 18:43:24.118444 2018] [:error] [pid 1881] [remote 172.31.30.131:0] self.models_module = import_module(models_module_name)
[Sun Dec 23 18:43:24.118511 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[Sun Dec 23 18:43:24.118625 2018] [:error] [pid 1881] [remote 172.31.30.131:0] __import__(name)
[Sun Dec 23 18:43:24.118687 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
[Sun Dec 23 18:43:24.118874 2018] [:error] [pid 1881] [remote 172.31.30.131:0] from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
[Sun Dec 23 18:43:24.118956 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
[Sun Dec 23 18:43:24.119098 2018] [:error] [pid 1881] [remote 172.31.30.131:0] class AbstractBaseUser(models.Model):
[Sun Dec 23 18:43:24.119159 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/models/base.py", line 124, in __new__
[Sun Dec 23 18:43:24.120069 2018] [:error] [pid 1881] [remote 172.31.30.131:0] new_class.add_to_class('_meta', Options(meta, app_label))
[Sun Dec 23 18:43:24.120155 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/models/base.py", line 325, in add_to_class
[Sun Dec 23 18:43:24.120229 2018] [:error] [pid 1881] [remote 172.31.30.131:0] value.contribute_to_class(cls, name)
[Sun Dec 23 18:43:24.120306 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/models/options.py", line 214, in contribute_to_class
[Sun Dec 23 18:43:24.120597 2018] [:error] [pid 1881] [remote 172.31.30.131:0] self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Sun Dec 23 18:43:24.120827 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
[Sun Dec 23 18:43:24.120943 2018] [:error] [pid 1881] [remote 172.31.30.131:0] return getattr(connections[DEFAULT_DB_ALIAS], item)
[Sun Dec 23 18:43:24.121023 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
[Sun Dec 23 18:43:24.121191 2018] [:error] [pid 1881] [remote 172.31.30.131:0] backend = load_backend(db['ENGINE'])
[Sun Dec 23 18:43:24.121260 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend
[Sun Dec 23 18:43:24.121347 2018] [:error] [pid 1881] [remote 172.31.30.131:0] return import_module('%s.base' % backend_name)
[Sun Dec 23 18:43:24.121415 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[Sun Dec 23 18:43:24.121495 2018] [:error] [pid 1881] [remote 172.31.30.131:0] __import__(name)
[Sun Dec 23 18:43:24.121550 2018] [:error] [pid 1881] [remote 172.31.30.131:0] File "/opt/python/run/venv/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 25, in <module>
[Sun Dec 23 18:43:24.121728 2018] [:error] [pid 1881] [remote 172.31.30.131:0] raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
[Sun Dec 23 18:43:24.121799 2018] [:error] [pid 1881] [remote 172.31.30.131:0] ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
Если я закомментирую свой словарь базы данных и открою представление, которое не запрашивает базу данных, я получаю 200 и содержимое, как и ожидалось.Если я затем раскомментирую словарь базы данных, я получу 500 независимо от того, какой просмотр я посещаю.
В моем requirements.txt
у меня есть Django==1.11.17
и psycopg2==2.7.5
.Я могу видеть из eb-activity.log
, где они успешно устанавливаются PIP при создании или обновлении среды.
Я действительно в растерянности относительно того, что может быть проблема на этом этапе.