Forums

WSGI Error - Django & Cookiecutter - So close

Getting the following error: when setting up my Django application, hoping someone might be able to assist

2018-03-03 07:01:12,197: Error running WSGI application
2018-03-03 07:01:12,198: ImportError: No module named 'pymysql'
2018-03-03 07:01:12,198:   File "/var/www/myapplication_pythonanywhere_com_wsgi.py", line 29, in <module>
2018-03-03 07:01:12,198:     application = get_wsgi_application()
2018-03-03 07:01:12,198: 
2018-03-03 07:01:12,198:   File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2018-03-03 07:01:12,198:     django.setup(set_prefix=False)
2018-03-03 07:01:12,199: 
2018-03-03 07:01:12,199:   File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 22, in setup
2018-03-03 07:01:12,199:     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2018-03-03 07:01:12,199: 
2018-03-03 07:01:12,199:   File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 53, in __getattr__
2018-03-03 07:01:12,199:     self._setup(name)
2018-03-03 07:01:12,199: 
2018-03-03 07:01:12,199:   File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 41, in _setup
2018-03-03 07:01:12,200:     self._wrapped = Settings(settings_module)
2018-03-03 07:01:12,200: 
2018-03-03 07:01:12,200:   File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 97, in __init__
2018-03-03 07:01:12,200:     mod = importlib.import_module(self.SETTINGS_MODULE)
2018-03-03 07:01:12,200: 
2018-03-03 07:01:12,200:   File "./config/settings/__init__.py", line 1, in <module>
2018-03-03 07:01:12,200:     import pymysql

The site works fine local, setting up in "production" following the steps form: http://cookiecutter-django.readthedocs.io/en/latest/deployment-on-pythonanywhere.html

The /var/www/myapplication_pythonanywhere_com_wsgi.py looks like below with the postactivate in the virtual environment looking similar

> import os import sys path = 'home/myapplication/myapplication/' if
> path not in sys.path:
>     sys.path.append(path)
> 
> os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings.production'
> os.environ['DJANGO_SECRET_KEY'] = 'is filled in correctly ''
> os.environ['DJANGO_ALLOWED_HOSTS'] =
> 'http://myapplication.pythonanywhere.com/'
> os.environ['DJANGO_ADMIN_URL'] =
> 'http://myapplication.pythonanywhere.com/something'
> os.environ['DJANGO_MAILGUN_API_KEY'] = ''
> os.environ['DJANGO_MAILGUN_SERVER_NAME'] = ''
> os.environ['MAILGUN_SENDER_DOMAIN'] = ''
> os.environ['DJANGO_AWS_ACCESS_KEY_ID'] = ''
> os.environ['DJANGO_AWS_SECRET_ACCESS_KEY'] = ''
> os.environ['DJANGO_AWS_STORAGE_BUCKET_NAME'] = ''
> os.environ['DATABASE_URL'] =
> 'mysql://myapplication:thepassowrd@myapplication.mysql.pythonanywhere-services.com/database$user'
> 
> from django.core.wsgi import get_wsgi_application application =
> get_wsgi_application()

Of course running pip install mysqlclient or pymysql is says that the Requirement already satisfied. Database seems to have set-up tables and everything ok so doesn't seems like an issue there

Any thoughts ? Any assistance would be greatly appericated

It might be a Python version difference. Your website is set up to use Python 3.5, and pip on its own will manage modules for Python 2.7. If you run

pip3.5 install --user pymysql

....then that will install the module for the right Python version.

thanks thats working now ... well almost, hoping you might be able to assist a little further Just an issues with the static files now. Getting an error 500 on my static files.

My production.py has this set

STATIC_ROOT = "/home/myusername/myapplication/static"
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    str(APPS_DIR.path('static')),

And on the Web application set url as /static/ and path from STATIC_ROOT

All seems to work fine when i run the collectstatic command runs through and gives 1468 static files copied to '/home/myusername/myapplicationname/static'.

Any thoughts?

Example from errorlog

2018-03-07 17:44:33 -------------------------------------------------------------------------------
2018-03-07 17:44:34 Content-Type: text/plain; charset="utf-8"#012MIME-Version: 1.0#012Content-Transfer-Encoding: quoted-printable#012Subject: [myapp]ERROR (EXTERNAL IP): Internal Server Error: /favicon.ico#012From: myapp <noreply@example.com>#012To: you@example.com#012Date: Wed, 07 Mar 2018 07:44:34 -0000#012Message-ID: <20180307074434.3.46248@localhost>#012#012Internal Server Error: /favicon.ico#012#012InvalidCacheBackendError at /favicon.ico#012Could not find backend 'django_redis.cache.RedisCache': No module named 'dj=#012ango_redis'#012#012Request Method: GET#012Request URL: https://myapp.pythonanywhere.com/favicon.ico#012Django Version: 1.10.8#012Python Executable: /usr/local/bin/uwsgi#012Python Version: 3.5.2#012Python Path: ['/var/www', '.', '', '/home/myapp/.local/lib/python3.5/=#012site-packages', '/var/www', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-=#012x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python=#0123.5/dist-packages', '/usr/lib/python3/dist-pac
2018-03-07 17:44:34 -------------------------------------------------------------------------------
2018-03-07 17:44:34 Content-Type: text/plain; charset="utf-8"#012MIME-Version: 1.0#012Content-Transfer-Encoding: quoted-printable#012Subject: [myapp]ERROR (EXTERNAL IP): Internal Server Error: /favicon.ico#012From: myapp <noreply@example.com>#012To: you@example.com#012Date: Wed, 07 Mar 2018 07:44:34 -0000#012Message-ID: <20180307074434.3.82200@localhost>#012#012Internal Server Error: /favicon.ico#012#012InvalidCacheBackendError at /favicon.ico#012Could not find backend 'django_redis.cache.RedisCache': No module named 'dj=#012ango_redis'#012#012Request Method: GET#012Request URL: https://myapp.pythonanywhere.com/favicon.ico#012Django Version: 1.10.8#012Python Executable: /usr/local/bin/uwsgi#012Python Version: 3.5.2#012Python Path: ['/var/www', '.', '', '/home/myapp/.local/lib/python3.5/=#012site-packages', '/var/www', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-=#012x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python=#0123.5/dist-packages', '/usr/lib/python3/dist-pac
2018-03-07 17:44:34 -------------------------------------------------------------------------------

Sorry for the slow turnaround on this! I suspect you might have moved things along since your last post, but I can see a different (and more helpfully-formatted) error in your error log right now -- it looks like you need to add something to your settings...?