Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Target WSGI script '/opt/python/current/app/core/wsgi.py' cannot be loaded as Python module

Tags:

I have problem with AWS+Django+React. I do this tutorial https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html . When i write "eb open" i have some trouble "Error reading /opt/python/current/app/webpack-stats.json. Are you sure webpack has generated the file and the path is correct?". However when I run project locally in my virtual environment, everything works perfectly.

Error 1 image Error 2 image

My code:

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-decor-env.env

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

Project structure Structure

I've spent so much time solving this issue... Any helpful advices would be great for me.

UPDATE: I decided my problem with S3, i watch my files on host and see that me file webpack-stats.json not push on AWS. I upload webpack-stats.json and rebuild my project, sucesfully compiling, but now i have new problem Internal Server Error 500 eb logs back:

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)

What i do wrong now? Thanks for attention..

like image 254
Audi Quattro 1992 Avatar asked Jun 01 '18 11:06

Audi Quattro 1992


1 Answers

I was having the same error, in my Django proyect in AWS using elasticbeanstalk, for anyone who is facing this issue I solved after many tries doing this:

  1. run "eb config" and check the route for the WSGIPath , that should be: WSGIPath: yourApp/wsgi.py

2)downgrade Django to version 2.1.1 , I was using Django a different one and somehow there was an incompatibility.

Hope it helps

like image 197
Cesar Tabares Avatar answered Sep 28 '22 17:09

Cesar Tabares