Django Internal Server 500 Error AWS Elastic-Beanstalk issue - python

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

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.

In my case error with sqllite
Remove Database settings from settings.py and try deploy
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
And then I configured with AWS RDS.

Related

Django AWS Elastic Beanstalk error ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

I know this error have come to many people and I have tried different solutions and none of them worked.
I am using aws eb cli.
I am using following command eb deploy to deploy my application to server.
Following are the configuration for my Django.
under .ebextensions directory, I have following 2 files:
1: 01_packages.config
packages:
yum:
git: []
python27-devel: []
mysql: []
mysql-devel: []
and another file is
2: 02_django.conf
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "settings.development"
"PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: src/wsgi.py
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
Following is my requirements.txt file after pip freeze in my local virtual environment.
requirements.txt
asn1crypto==0.24.0
awsebcli==3.17.1
backports.ssl-match-hostname==3.5.0.1
botocore==1.14.17
cement==2.8.2
cent==2.1.0
centrifuge==0.8.4
certifi==2017.11.5
cffi==1.11.2
chardet==3.0.4
colorama==0.3.9
cryptography==2.1.4
Django==1.8.18
django-colorfield==0.1.14
django-countries==5.0
django-debug-toolbar==1.9.1
django-environ==0.4.4
django-multiselectfield==0.1.8
django-simple-history==1.9.1
django-sslserver==0.20
docutils==0.15.2
enum34==1.1.6
future==0.16.0
google-api-python-client==1.6.4
hiredis==0.2.0
html5lib==1.0b8
httplib2==0.10.3
icalendar==4.0.0
idna==2.6
ipaddress==1.0.18
jmespath==0.9.4
jsonschema==2.4.0
mysqlclient==1.4.6
oauth2client==2.0.0
oauthclient==1.0.3
olefile==0.44
pathspec==0.5.9
paypalrestsdk==1.13.1
pdfcrowd==4.0.1
phonenumbers==8.8.6
Pillow==4.3.0
pyasn1==0.3.7
pyasn1-modules==0.1.5
pycparser==2.18
PyJWT==1.5.3
pyOpenSSL==17.5.0
PyPDF2==1.26.0
pypiwin32==219
pytesseract==0.1.7
python-dateutil==2.6.1
pytz==2017.3
PyYAML==5.2
reportlab==3.4.0
requests==2.18.4
rsa==3.4.2
semantic-version==2.5.0
six==1.11.0
sockjs-tornado==1.0.1
sqlparse==0.2.4
termcolor==1.1.0
toredis-fork==0.1.4
tornado==4.2.1
toro==0.8
twilio==6.9.1
uritemplate==3.0.0
urllib3==1.22
wcwidth==0.1.8
webencodings==0.5.1
xhtml2pdf==0.2.2
I kept this in my root directory.
When I run eb deploy
it deploys successfully.
but when I run the browser to my url.
I get this Internal Server Error page.
So I tried to look in to the log files on the server under /var/log/httpd/error_log
i get the following error:
[Mon Feb 24 17:56:57.227427 2020] [:error] [pid 8054] [remote 101.50.93.65:188] mod_wsgi (pid=8054): Target WSGI script '/opt/python/current/app/src/wsgi.py' cannot be loaded as Python module.
[Mon Feb 24 17:56:57.227450 2020] [:error] [pid 8054] [remote 101.50.93.65:188] mod_wsgi (pid=8054): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 17:56:57.227466 2020] [:error] [pid 8054] [remote 101.50.93.65:188] Traceback (most recent call last):
[Mon Feb 24 17:56:57.227483 2020] [:error] [pid 8054] [remote 101.50.93.65:188] File "/opt/python/current/app/src/wsgi.py", line 17, in <module>
[Mon Feb 24 17:56:57.227585 2020] [:error] [pid 8054] [remote 101.50.93.65:188] application = get_wsgi_application()
[Mon Feb 24 17:56:57.227599 2020] [:error] [pid 8054] [remote 101.50.93.65:188] File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Mon Feb 24 17:56:57.227627 2020] [:error] [pid 8054] [remote 101.50.93.65:188] django.setup()
[Mon Feb 24 17:56:57.227634 2020] [:error] [pid 8054] [remote 101.50.93.65:188] File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
[Mon Feb 24 17:56:57.227645 2020] [:error] [pid 8054] [remote 101.50.93.65:188] apps.populate(settings.INSTALLED_APPS)
[Mon Feb 24 17:56:57.227651 2020] [:error] [pid 8054] [remote 101.50.93.65:188] File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 78, in populate
[Mon Feb 24 17:56:57.227662 2020] [:error] [pid 8054] [remote 101.50.93.65:188] raise RuntimeError("populate() isn't reentrant")
[Mon Feb 24 17:56:57.227676 2020] [:error] [pid 8054] [remote 101.50.93.65:188] RuntimeError: populate() isn't reentrant
So I kept Googling, and found a post suggested to change wsgi file, and I did and then this error updated to the following lines of code.
[Mon Feb 24 18:23:12.169850 2020] [mpm_prefork:notice] [pid 9081] AH00169: caught SIGTERM, shutting down
[Mon Feb 24 18:23:13.289449 2020] [suexec:notice] [pid 10286] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Feb 24 18:23:13.305290 2020] [so:warn] [pid 10286] AH01574: module wsgi_module is already loaded, skipping
[Mon Feb 24 18:23:13.307373 2020] [http2:warn] [pid 10286] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
[Mon Feb 24 18:23:13.307384 2020] [http2:warn] [pid 10286] AH02951: mod_ssl does not seem to be enabled
[Mon Feb 24 18:23:13.307990 2020] [lbmethod_heartbeat:notice] [pid 10286] AH02282: No slotmem from mod_heartmonitor
[Mon Feb 24 18:23:13.308050 2020] [:warn] [pid 10286] mod_wsgi: Compiled for Python/2.7.13.
[Mon Feb 24 18:23:13.308057 2020] [:warn] [pid 10286] mod_wsgi: Runtime using Python/2.7.16.
[Mon Feb 24 18:23:13.311200 2020] [mpm_prefork:notice] [pid 10286] AH00163: Apache/2.4.41 (Amazon) mod_wsgi/3.5 Python/2.7.16 configured -- resuming normal operations
[Mon Feb 24 18:23:13.311217 2020] [core:notice] [pid 10286] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Mon Feb 24 18:23:16.367182 2020] [:error] [pid 10293] [remote 127.0.0.1:0] mod_wsgi (pid=10293): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:23:16.367240 2020] [:error] [pid 10293] [remote 127.0.0.1:0] RuntimeError: response has not been started
[Mon Feb 24 18:23:17.744228 2020] [:error] [pid 10291] [remote 127.0.0.1:0] mod_wsgi (pid=10291): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:23:17.744288 2020] [:error] [pid 10291] [remote 127.0.0.1:0] RuntimeError: response has not been started
[Mon Feb 24 18:23:19.116825 2020] [:error] [pid 10292] [remote 127.0.0.1:0] mod_wsgi (pid=10292): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:23:19.116892 2020] [:error] [pid 10292] [remote 127.0.0.1:0] RuntimeError: response has not been started
[Mon Feb 24 18:23:20.493432 2020] [:error] [pid 10418] [remote 127.0.0.1:0] mod_wsgi (pid=10418): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:23:20.493489 2020] [:error] [pid 10418] [remote 127.0.0.1:0] RuntimeError: response has not been started
[Mon Feb 24 18:36:44.987693 2020] [:error] [pid 10443] [remote 95.105.12.68:0] mod_wsgi (pid=10443): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:36:44.987766 2020] [:error] [pid 10443] [remote 95.105.12.68:0] RuntimeError: response has not been started
[Mon Feb 24 18:55:28.298121 2020] [:error] [pid 10468] [remote 101.50.93.65:0] mod_wsgi (pid=10468): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:55:28.298180 2020] [:error] [pid 10468] [remote 101.50.93.65:0] RuntimeError: response has not been started
[Mon Feb 24 18:55:30.126198 2020] [:error] [pid 10499] [remote 101.50.93.65:0] mod_wsgi (pid=10499): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:55:30.126260 2020] [:error] [pid 10499] [remote 101.50.93.65:0] RuntimeError: response has not been started
[Mon Feb 24 18:55:31.671293 2020] [:error] [pid 10973] [remote 101.50.93.65:0] mod_wsgi (pid=10973): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:55:31.671358 2020] [:error] [pid 10973] [remote 101.50.93.65:0] RuntimeError: response has not been started
[Mon Feb 24 18:55:32.858757 2020] [:error] [pid 11606] [remote 101.50.93.65:0] mod_wsgi (pid=11606): Exception occurred processing WSGI script '/opt/python/current/app/src/wsgi.py'.
[Mon Feb 24 18:55:32.858821 2020] [:error] [pid 11606] [remote 101.50.93.65:0] RuntimeError: response has not been started
and this is the new wsgi.py file.
import os
import logging
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.development")
from django.core.wsgi import get_wsgi_application
# application = get_wsgi_application()
env_variables_to_pass = ['DJANGO_SETTINGS_MODULE', ]
def application(environ, start_response):
if environ['mod_wsgi.process_group'] != '':
import signal
os.kill(os.getpid(), signal.SIGINT)
return ["killed"]
and following was the old wsgi.py file
import os
import logging
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.development")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
env_variables_to_pass = ['DJANGO_SETTINGS_MODULE', ]
So then I tried to run application on the server using python manage.py runserver as there was nothing else to do to fix this and I was not sure where the problem is.
So I did ssh and I did used the virtualenvironment of server that was already there created by EB.
after running python manage.py runserver.
I get this following error.
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
So I tried to follow any advice that I could see available on google.
I tried pip install mysqlclient
I get this error.
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
sh: mariadb_config: command not found
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-MxFUOd/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "setup_posix.py", line 61, in get_config
libs = mysql_config("libs")
File "setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (_mysql_config_path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-MxFUOd/mysqlclient/
I tried both
pip install mysqlclient --no-cache-dir
and
pip install mysqlclient
It's Centos server so I cannot do the sudo apt-get commands.
Only yum commands work.
I tried this following command with sudo
sudo pip install mysql-connector-python
But I think this will be installed globally rather than env.
So I tried without sudo, and it gave permission error.
I used other commands to install mysql both with sudo and not sudo.
pip install pymysql
sudo yum install python-mysqldb
No matter what I do I get this MySQL error.
I don't want to move to other database as I would have to move data as well.
UPDATE
from given suggession of #Arun K i ran this following command
which mysql_config
i got this following response.
/usr/bin/which: no mysql_config in (/opt/python/run/venv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin)
in my case on on 64bit Amazon Linux 2/3.0.1
i had to install the following via *.config inside .ebextensions
packages:
yum:
python3-devel: []
mariadb-devel: []
gcc: []
Try running
sudo yum install mysql-devel gcc python-devel
Then
pip install mysqlclient
Why don't you use docker and run the Django app as a container? The elastic beanstalk also supports the docker type. There are so many articles on the internet detailing the steps. you do not have to worry about centos.
Reference:
Django on Docler

ModuleNotFoundError: No module named 'django' while deploying to ElasticBeanstalk

Tried multiple solutions online but couldnt get it working !
Basically my application is deployed but http response is "Internal Server Error".
On investigating EB logs i found the following traceback.
[Sat Jun 08 10:28:56.880823 2019] [:error] [pid 4776] [remote 172.31.4.251:180] Traceback (most recent call last):
[Sat Jun 08 10:28:56.880846 2019] [:error] [pid 4776] [remote 172.31.4.251:180] File "/opt/python/current/app/modelforms/modelforms/wsgi.py", line 12, in <module>
[Sat Jun 08 10:28:56.880863 2019] [:error] [pid 4776] [remote 172.31.4.251:180] from django.core.wsgi import get_wsgi_application
[Sat Jun 08 10:28:56.880878 2019] [:error] [pid 4776] [remote 172.31.4.251:180] ModuleNotFoundError: No module named 'django'
[Sat Jun 08 10:29:10.828039 2019] [:error] [pid 4776] [remote 172.31.42.54:180] mod_wsgi (pid=4776): Target WSGI script '/opt/python/current/app/modelforms/modelforms/wsgi.py' cannot be loaded as Python module.
[Sat Jun 08 10:29:10.828089 2019] [:error] [pid 4776] [remote 172.31.42.54:180] mod_wsgi (pid=4776): Exception occurred processing WSGI script '/opt/python/current/app/modelforms/modelforms/wsgi.py'.
My requirements.txt is placed in all directories and yet django module is not recognised. It seems it hasn't been installed at first place.
The file's contents are:
Django==2.2.1
Pillow==6.0.0
pytz==2019.1
sorl-thumbnail==12.5.0
sqlparse==0.3.0
Any help is appreciated.
EDIT1:
I dont have ebextentions setup, however the same config's are present when i run " eb config"
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: modelforms/modelforms/wsgi.py
aws:elasticbeanstalk:container:python:staticfiles:
/static/: static/
aws:elasticbeanstalk:environment:
EnvironmentType: LoadBalanced
ExternalExtensionsS3Bucket: null
ExternalExtensionsS3Key: null
LoadBalancerType: application
ServiceRole: aws-elasticbeanstalk-service-role
Try adding your DJANGO_SETTINGS_MODULE and PYTHONPATH to the config
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "modelforms.settings"
"PYTHONPATH": "/opt/python/current/app/modelforms:$PYTHONPATH"
Also, check the Health dashboard and make sure it shows as deployed before testing

Flask app deployment - ImportError: No module named 'app'

Strange one - I've tried and tried to get this Flask app going - something seems to be going wrong.
$ pwd inside the Flask app gives:
/home/winduplordvexxos/winduplordvexxos.com/windupflaskvexxos
$ ls inside the Flask app gives:
__init__.py __pycache__ vexxos.py windupflaskvexxos.wsgi
__init__.py is empty.
vexxos.py:
from flask import Flask
app = Flask(__name__)
#app.route('/')
def api():
return 'Wind Up Lord Vexxos API'
if __name__ == "__main__":
app.run(host='0.0.0.0')
windupflaskvexxos.wsgi:
activate_this = '/home/winduplordvexxos/winduplordvexxos.com/winduplordvexxos_env/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
import os, sys
cwd = os.getcwd()
sys.path.insert(0, cwd)
try:
from .vexxos import app as application
except Exception: #ImportError
from vexxos import app as application
However, all I see on the front end is:
/etc/apache2/site-available/000-default.conf:
<VirtualHost *:80>
ServerAlias flask.winduplordvexxos.com
ServerAdmin admin#winduplordvexxos.com
WSGIDaemonProcess windupflaskvexxos.com user=winduplordvexxos group=winduplordvexxos threads=5
WSGIScriptAlias / /home/winduplordvexxos/winduplordvexxos.com/windupflaskvexxos/windupflaskvexxos.wsgi
<Directory /home/winduplordvexxos/winduplordvexxos.com/windupflaskvexxos/>
WSGIProcessGroup windupflaskvexxos.com
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Require all granted
</Directory>
</VirtualHost>
Checking the apache error logs has given me:
[Fri Oct 13 23:05:14.650945 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] mod_wsgi (pid=15561): Target WSGI script '/home/winduplordve$
[Fri Oct 13 23:05:14.651088 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] mod_wsgi (pid=15561): Exception occurred processing WSGI scr$
[Fri Oct 13 23:05:14.657996 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] Traceback (most recent call last):
[Fri Oct 13 23:05:14.658060 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] File "/home/winduplordvexxos/winduplordvexxos.com/windupfl$
[Fri Oct 13 23:05:14.658071 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] from .vexxos import app as application
[Fri Oct 13 23:05:14.658098 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] SystemError: Parent module '' not loaded, cannot perform rel$
[Fri Oct 13 23:05:14.658131 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859]
[Fri Oct 13 23:05:14.658146 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] During handling of the above exception, another exception oc$
[Fri Oct 13 23:05:14.658156 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859]
[Fri Oct 13 23:05:14.658180 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] Traceback (most recent call last):
[Fri Oct 13 23:05:14.658229 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] File "/home/winduplordvexxos/winduplordvexxos.com/windupfl$
[Fri Oct 13 23:05:14.658248 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] from vexxos import app as application
[Fri Oct 13 23:05:14.658286 2017] [wsgi:error] [pid 15561:tid 140103054321408] [remote 109.149.163.9:59859] ImportError: No module named 'vexxos'
[Fri Oct 13 23:05:14.690252 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] mod_wsgi (pid=15561): Target WSGI script '/home/winduplordve$
[Fri Oct 13 23:05:14.690318 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] mod_wsgi (pid=15561): Exception occurred processing WSGI scr$
[Fri Oct 13 23:05:14.690468 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] Traceback (most recent call last):
[Fri Oct 13 23:05:14.690515 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] File "/home/winduplordvexxos/winduplordvexxos.com/windupfl$
[Fri Oct 13 23:05:14.690525 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] from .vexxos import app as application
[Fri Oct 13 23:05:14.690549 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] SystemError: Parent module '' not loaded, cannot perform rel$
[Fri Oct 13 23:05:14.690566 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858]
[Fri Oct 13 23:05:14.690573 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] During handling of the above exception, another exception oc$
[Fri Oct 13 23:05:14.690577 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858]
[Fri Oct 13 23:05:14.690589 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] Traceback (most recent call last):
[Fri Oct 13 23:05:14.690610 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] File "/home/winduplordvexxos/winduplordvexxos.com/windupfl$
[Fri Oct 13 23:05:14.690619 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] from vexxos import app as application
[Fri Oct 13 23:05:14.690637 2017] [wsgi:error] [pid 15561:tid 140103087892224] [remote 109.149.163.9:59858] ImportError: No module named 'vexxos'
I've tried a number of things, try except on the module import etc but nothing seems to work...can anyone help with this?
You likely need to tell mod_wsgi where your code is using the python-path option to WSGIDaemonProcess. Your import in the WSGI script file also looks wrong.
For python-path you likely want:
python-path=/home/winduplordvexxos/winduplordvexxos.com
The import should then be:
from windupflaskvexxos import app as application
or if app not pulled in by __init__.py, use:
from windupflaskvexxos.vexxos import app as application
Also read up on the preferred way of setting up a virtual environment with mod_wsgi. The way you are using is not the recommended way.
http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html

Mysql not working with python 3.6 and django 1.9

I am trying to connect mysql db with django 1.9 and python version is 3.6. With database connection string I am getting the below error. If I comment out the database connection string the site is loading fine. Can anybody tell what is wrong in this.
[Wed Apr 05 07:01:08.287609 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] mod_wsgi (pid=29791): Target WSGI script '/home/abhadran/test/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[Wed Apr 05 07:01:08.287675 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] mod_wsgi (pid=29791): Exception occurred processing WSGI script '/home/abhadran/test/mysite/mysite/wsgi.py'.
[Wed Apr 05 07:01:08.287705 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] Traceback (most recent call last):
[Wed Apr 05 07:01:08.287740 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] File "/home/abhadran/test/mysite/mysite/wsgi.py", line 20, in <module>
[Wed Apr 05 07:01:08.287787 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] application = get_wsgi_application()
[Wed Apr 05 07:01:08.287798 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] File "/home/abhadran/myenv/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Wed Apr 05 07:01:08.290733 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] django.setup(set_prefix=False)
[Wed Apr 05 07:01:08.290756 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] File "/home/abhadran/myenv/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
[Wed Apr 05 07:01:08.290779 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] apps.populate(settings.INSTALLED_APPS)
[Wed Apr 05 07:01:08.290790 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] File "/home/abhadran/myenv/lib/python3.6/site-packages/django/apps/registry.py", line 78, in populate
[Wed Apr 05 07:01:08.291738 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] raise RuntimeError("populate() isn't reentrant")
[Wed Apr 05 07:01:08.291768 2017] [wsgi:error] [pid 29791] [remote 173.1.101.95:52570] RuntimeError: populate() isn't reentrant
My pip freeze
Django==1.9.12
django-tastypie==0.13.3
mod-wsgi==4.5.15
mysql-connector-python==2.0.4
mysqlclient==1.3.10
PyMySQL==0.6
python-dateutil==2.6.0
python-mimeparse==1.6.0
requests==2.13.0
six==1.10.0
DB Settings we are using to try to connect to the Mysql
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'AAAAAAAAAAAAAAAAA',
'NAME': 'ZZZZZZZZZZZZZZZZ',
'USER': 'YYYYYYYYYYYYYYYY',
'PASSWORD': 'XXXXXXXXXXXX',
'PORT': '3306',
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB',
},
}
}
Usually, this error means there is an error in the Django project somewhere. It could be hard to locate.
You can try multiple solutions like:
1. Restart Apache
2. Execute makemigrations and migrate Django commands
3. Modify your wsgi.py file so you can manage the exception
A little note, in the line File "/home/abhadran/myenv/lib/python3.6/site-packages/django/apps/registry.py" indicate that you're using Python 3.6 and not Python 3.5 as you mentioned in your description.
Python 3.6 is officially supported until Django 1.11, so you maybe must upgrade your Django version or downgrade your Python in your venv.
Related posts:
- Post 1
- Post 2
- Post 3
- Post 4
- Post 5

Error deploying Django Application

I am trying to deploy my first Django application on a server with Ubuntu 14.04.1 LTS.
I installed apache and something else:
apt-get install apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
Then I installed wsgi module:
apt-get install libapache2-mod-wsgi
I edited the ports.conf to listen on port 8080, as I already have another server on port 80 where I host html+js+css resources (they are correctly available).
After this preparation step, I moved my Django application on the new Apache server, specifically into the html directory. Then edited the apache2.conf file by adding the following:
WSGIScriptAlias / /var/www/html/MyProjectName/wsgi.py
WSGIPythonPath /var/www/html/MyProjectName
<Directory /var/www/html/MyProjectName>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
The rest of configuration directives is the default I get after installing Apache with the given commands.
Then, I noticed that in the mods-available folder, I had the wsgi module, but not in the mods-enabled folder, so I created a symbolink link into this last folder.
When I start Apache, if I open localhost:8080, I get an internal server error. Accessing the error.log file, I see the following:
[Mon Mar 09 16:38:20.730865 2015] [mpm_event:notice] [pid 24379:tid 140525609281408] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Mon Mar 09 16:38:20.731257 2015] [core:notice] [pid 24379:tid 140525609281408] AH00094: Command line: '/usr/sbin/apache2'
[Mon Mar 09 16:38:28.673948 2015] [:error] [pid 24383:tid 140525514131200] [client 127.0.0.1:41038] mod_wsgi (pid=24383): Target WSGI script '/var/www/html/MyProjectName/wsgi.py' cannot be loaded as Python module.
[Mon Mar 09 16:38:28.674120 2015] [:error] [pid 24383:tid 140525514131200] [client 127.0.0.1:41038] mod_wsgi (pid=24383): Exception occurred processing WSGI script '/var/www/html/MyProjectName/wsgi.py'.
[Mon Mar 09 16:38:28.674240 2015] [:error] [pid 24383:tid 140525514131200] [client 127.0.0.1:41038] Traceback (most recent call last):
[Mon Mar 09 16:38:28.674299 2015] [:error] [pid 24383:tid 140525514131200] [client 127.0.0.1:41038] File "/var/www/html/MyProjectName/wsgi.py", line 13, in <module>
[Mon Mar 09 16:38:28.674438 2015] [:error] [pid 24383:tid 140525514131200] [client 127.0.0.1:41038] from django.core.wsgi import get_wsgi_application
[Mon Mar 09 16:38:28.674480 2015] [:error] [pid 24383:tid 140525514131200] [client 127.0.0.1:41038] ImportError: No module named django.core.wsgi
Where do I start understanding the problem?
My understanding is that somehow the Apache WSGI module is not working.
For completeness, the wsgi.py file I am pointing at looks like this:
import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyProjectName.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
sys.path.append('/var/www/')
sys.path.append('/var/www/html/')
sys.path.append('/var/www/html/MyProjectName')
The settings file is as follow:
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SECRET_KEY = '<some_key_here>'
DEBUG = False
TEMPLATE_DEBUG = False
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'anothercustomapp',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'MyProjectName.urls'
WSGI_APPLICATION = 'MyProjectName.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'MyDatabaseName',
'USER' : '<username>',
'PASSWORD' : '<password>',
}
}
SERIALIZATION_MODULES = {
'json': 'wadofstuff.django.serializers.custom_json'
}
LANGUAGE_CODE = 'it-IT'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
At the path /var/www/html/ I have the following structure:
A folder called MyProjectName, containing the wsgi.py file, as well as a settings.py file, urls.py and an empty init.py
A folder called anothercustomapp, containing urls, models, views and admin python files, other than an empty init.py
A folder called wadostuff, used to serialize to json and containing the same files as anothercustomapp (in terms of names)
================EDIT================
After installing Django and python-mysqldb with the following commands:
apt-get install python-setuptools
easy_install django
apt-get install python-mysqldb
I end up having the following error.log:
[Mon Mar 09 16:52:13.610937 2015] [mpm_event:notice] [pid 24789:tid 139911380785024] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Mon Mar 09 16:52:13.611288 2015] [core:notice] [pid 24789:tid 139911380785024] AH00094: Command line: '/usr/sbin/apache2'
[Mon Mar 09 16:52:18.056083 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] mod_wsgi (pid=24792): Target WSGI script '/var/www/html/MyProjectName/wsgi.py' cannot be loaded as Python module.
[Mon Mar 09 16:52:18.056256 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] mod_wsgi (pid=24792): Exception occurred processing WSGI script '/var/www/html/MyProjectName/wsgi.py'.
[Mon Mar 09 16:52:18.056302 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] Traceback (most recent call last):
[Mon Mar 09 16:52:18.056346 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] File "/var/www/html/MyProjectName/wsgi.py", line 14, in <module>
[Mon Mar 09 16:52:18.056485 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] application = get_wsgi_application()
[Mon Mar 09 16:52:18.056514 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] File "/usr/local/lib/python2.7/dist-packages/Django-1.7.6-py2.7.egg/django/core/wsgi.py", line 14, in get_wsgi_application
[Mon Mar 09 16:52:18.072789 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] django.setup()
[Mon Mar 09 16:52:18.072882 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] File "/usr/local/lib/python2.7/dist-packages/Django-1.7.6-py2.7.egg/django/__init__.py", line 20, in setup
[Mon Mar 09 16:52:18.088060 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Mar 09 16:52:18.088166 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] File "/usr/local/lib/python2.7/dist-packages/Django-1.7.6-py2.7.egg/django/conf/__init__.py", line 46, in __getattr__
[Mon Mar 09 16:52:18.097590 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] self._setup(name)
[Mon Mar 09 16:52:18.097632 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] File "/usr/local/lib/python2.7/dist-packages/Django-1.7.6-py2.7.egg/django/conf/__init__.py", line 42, in _setup
[Mon Mar 09 16:52:18.097692 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] self._wrapped = Settings(settings_module)
[Mon Mar 09 16:52:18.097725 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] File "/usr/local/lib/python2.7/dist-packages/Django-1.7.6-py2.7.egg/django/conf/__init__.py", line 98, in __init__
[Mon Mar 09 16:52:18.097778 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] % (self.SETTINGS_MODULE, e)
[Mon Mar 09 16:52:18.097833 2015] [:error] [pid 24792:tid 139911285634816] [client 127.0.0.1:41213] ImportError: Could not import settings 'MyProjectName.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named MyProjectName.settings

Categories