Django Internal Server 500 Error AWS Elastic-Beanstalk issue

Jwoozy picture Jwoozy · Oct 20, 2016 · Viewed 8.8k times · Source

How do I fix the Django Internal Server 500 error on an AWS eb deployed application?

Do I need to change my allowed hosts in my base.py file to have the ip address of the ec2 in elasticbeanstalk?

# SECURITY WARNING: keep the secret key used in production secret!
# Raises ImproperlyConfigured exception if SECRET_KEY not in os.environ
SECRET_KEY = env('SECRET_KEY')

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = (
    'django.contrib.auth',
    'django_admin_bootstrapped',
    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

...

STATIC_URL = '/static/'

ALLOWED_HOSTS = []

...

I enabled DEBUG and ran eb config, and eb logs. The eb deploy values are displayed below, and the eb logs values below that. How do you fix the issue that the "No module named django?"

    Creating application version archive "app-3e17-161020_112522".
Uploading pronet/app-3e17-161020_112522.zip to S3. This may take a while.
Upload Complete.
INFO: Environment update is starting.                               
INFO: Deploying new version to instance(s).                         
INFO: New application version was deployed to running EC2 instances.
INFO: Environment update completed successfully. 

Provided below are the output from eb logs.

============= i-0b11de8b8521ea5c0 ==============
-------------------------------------
/var/log/httpd/error_log
-------------------------------------
[Thu Oct 20 17:46:59.414032 2016] [:error] [pid 11268] 
[remote 172.31.5.67:41390] Traceback (most recent call last):

[Thu Oct 20 17:46:59.414077 2016] [:error] [pid 11268] 
[remote 172.31.5.67:41390]   File "/opt/python/current/app/pronet/src/pronet/wsgi.py", line 12, in <module>

[Thu Oct 20 17:46:59.414083 2016] [:error] [pid 11268] 
[remote 172.31.5.67:41390]     from django.core.wsgi import get_wsgi_application

[Thu Oct 20 17:46:59.414104 2016] [:error] [pid 11268] 
[remote 172.31.5.67:41390] ImportError: No module named 'django'

[Thu Oct 20 17:47:00.046644 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Target WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py' cannot be loaded as Python module.

[Thu Oct 20 17:47:00.046704 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Exception occurred processing WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py'.

[Thu Oct 20 17:47:00.046738 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] Traceback (most recent call last):

[Thu Oct 20 17:47:00.046784 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182]   File "/opt/python/current/app/pronet/src/pronet/wsgi.py", line 12, in <module>

[Thu Oct 20 17:47:00.046789 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182]     from django.core.wsgi import get_wsgi_application

[Thu Oct 20 17:47:00.046810 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] ImportError: No module named 'django'

[Thu Oct 20 17:47:01.340552 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Target WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py' cannot be loaded as Python module.

[Thu Oct 20 17:47:01.340603 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] mod_wsgi (pid=11268): Exception occurred processing WSGI script '/opt/python/current/app/pronet/src/pronet/wsgi.py'.

[Thu Oct 20 17:47:01.340653 2016] [:error] [pid 11268] [remote 172.31.5.67:43182] Traceback (most recent call last):

[Thu Oct 20 17:47:01.340701 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182]   File "/opt/python/current/app/pronet/src/pronet/wsgi.py", line 12, in <module>

[Thu Oct 20 17:47:01.340706 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182]     from django.core.wsgi import get_wsgi_application

[Thu Oct 20 17:47:01.340728 2016] [:error] [pid 11268] 
[remote 172.31.5.67:43182] ImportError: No module named 'django'

link to github project. You can view all the code here

https://github.com/IantheFlyingHawaiian/Pronet

Answer

Peter Li picture Peter Li · Sep 2, 2017

Did you do this?

pip freeze > requirements.txt

If you didn't, AWS will not know that it should install Django and other dependencies on your EC2 instances for your deployment.