AWS Target WSGI脚本'/opt/python/current/app/core/wsgi.py'无法作为Python模块加载

时间:2018-06-01 11:13:10

标签: django apache amazon-web-services mod-wsgi

我对AWS + Django + React有疑问。我做这个教程https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html。当我写“eb open”时我遇到了一些麻烦“读取/opt/python/current/app/webpack-stats.json时出错。你确定webpack生成了文件,路径是否正确?”。但是,当我在我的虚拟环境中本地运行项目时,一切都运行良好。

Error 1 image Error 2 image

我的代码:

settings.py

ALLOWED_HOSTS = ['django-decor-env.ffp8hmcfus.us-west-2.elasticbeanstalk.com', '*']
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': ['core/templates'],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},
]
STATIC_URL = '/static/'
STATIC_ROOT = "core/staticfiles" - update path.
STATICFILES_DIRS = [
   os.path.join(BASE_DIR, 'core/static'),
]
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR

# Webpack config
WEBPACK_LOADER = {
'DEFAULT': {
    'CACHE': not DEBUG,
    'BUNDLE_DIR_NAME': '/',  # must end with slash
    'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
    'POLL_INTERVAL': 0.1,
    'TIMEOUT': None,
  }
}

.exbetensions / python.config

option_settings:
  aws:elasticbeanstalk:container:python:
  WSGIPath: decor/core/wsgi.py

.elasticbeanstalk / Django的装饰-env.env

aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: core/wsgi.py

项目结构Structure

我花了很多时间来解决这个问题......任何有用的建议对我来说都很棒。

更新 我决定使用S3的问题,我在主机上查看我的文件,看到我的文件webpack-stats.json没有在AWS上推送。我上传webpack-stats.json并重建我的项目,进行了成功编译,但现在我遇到了新问题Internal Server Error 500 eb logs回复:

mod_wsgi (pid=3438): Target WSGI script
'/opt/python/current/app/core/wsgi.py' cannot be loaded as Python module.
[Tue Jun 12 22:43:17.606738 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
mod_wsgi (pid=3438): Exception occurred processing WSGI script
'/opt/python/current/app/core/wsgi.py'.
[Tue Jun 12 22:43:17.606898 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
Traceback (most recent call last):
[Tue Jun 12 22:43:17.606955 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
File "/opt/python/current/app/core/wsgi.py", line 21, in <module>
[Tue Jun 12 22:43:17.606959 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
application = get_wsgi_application()
[Tue Jun 12 22:43:17.606965 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
File "/opt/python/run/venv/local/lib/python3.6/site
packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Tue Jun 12 22:43:17.606967 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
django.setup(set_prefix=False)
[Tue Jun 12 22:43:17.606972 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
File "/opt/python/run/venv/local/lib/python3.6/site
packages/django/__init__.py", line 19, in setup
[Tue Jun 12 22:43:17.606974 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)

我现在做错了什么?感谢您的关注..

2 个答案:

答案 0 :(得分:3)

我在AWS中使用elasticbeanstalk的Django proyect中遇到了相同的错误,对于面临此问题的任何人,我在多次尝试后解决了这个问题:

  1. 运行“ eb config”并检查WSGIPath的路由,该路由应为: WSGIPath:yourApp / wsgi.py

2)将Django降级到2.1.1版,我使用的Django是另一种版本,因此不兼容。

希望有帮助

答案 1 :(得分:0)

你运行$ eb logs了吗?你运行 import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<app_name>.settings")了吗 尝试ssh进入机器并查看它创建文件的位置。

wsgi错误很可能是您没有正确导入模块。它应该像

{{1}}