I am trying to deploy my webapp on PythonAnywhere and am running into an issue which is just giving me a Error code: Unhandled Exception page. I am getting this error below in the error log:
2016-07-21 06:41:49,331 :Error running WSGI application
Traceback (most recent call last):
File "/bin/user_wsgi_wrapper.py", line 154, in __call__
app_iterator = self.app(environ, start_response)
File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
raise e
File "/bin/user_wsgi_wrapper.py", line 154, in __call__
app_iterator = self.app(environ, start_response)
File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
raise e
File "/bin/user_wsgi_wrapper.py", line 179, in <module>
application = load_wsgi_application()
File "/bin/user_wsgi_wrapper.py", line 175, in load_wsgi_application
return __import__(os.environ['WSGI_MODULE'], globals(), locals(), ['application']).application
File "/var/www/www_mywandermust_com_wsgi.py", line 12, in <module>
application = StaticFilesHandler(get_wsgi_application())
File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup()
File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named 'allauth'
I have already installed django-allauth in the server system and everything works perfectly on my local installation. I am also able to get the path in the console to allauth:
(venv) 06:49 ~/carmen (master)$ python -i /var/www/www_mywandermust_com_wsgi.py
>>> import allauth
>>> print (allauth)
<module 'allauth' from '/home/gsussman/carmen/venv/lib/python3.5/site-packages/allauth/__init__.py'>
Here is my WSGI file:
import os
import sys
path = '/home/gsussman/carmen' # use your own username here
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'travelapp.settings'
from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler
application = StaticFilesHandler(get_wsgi_application())
allauth is installed in a virtualenv (it's called venv). Your web app is clearly not using that virtualenv (the Django referred to in the traceback is in /usr/local, not in venv)
Related
I'm upgrading from django 1.6.5 to django 1.9, and in the process upgrading several middleware classes. Some of those middleware classes use models during the process_request or process_response phases. However, I'm getting a AppRegistryNotReady: Apps aren't loaded yet. error attempting to use them.
Is there a way to import models during middleware?
Should I move my import statements into the process_request / process_response methods?
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/newrelic-2.50.0.39/newrelic/api/web_transaction.py", line 1329, in _nr_wsgi_application_wrapper_
result = wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/newrelic-2.50.0.39/newrelic/api/web_transaction.py", line 1329, in _nr_wsgi_application_wrapper_
result = wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 158, in __call__
self.load_middleware()
File "/usr/local/lib/python2.7/dist-packages/newrelic-2.50.0.39/newrelic/common/object_wrapper.py", line 302, in _wrapper
result = wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 51, in load_middleware
mw_class = import_string(middleware_path)
File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 20, in import_string
module = import_module(module_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/web/MyJobs/MyJobs/apache/../middleware.py", line 9, in <module>
from django.contrib.sites.models import Site
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sites/models.py", line 83, in <module>
class Site(models.Model):
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
AppRegistryNotReady: Apps aren't loaded yet.
You need to use the new API to get a WSGI handler:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
This will call django.setup() for you, which will populate the app registry.
I'm trying to setup endless_pagination, I've followed the documentation but getting an error:
Traceback (most recent call last):
File "/bin/user_wsgi_wrapper.py", line 154, in __call__
app_iterator = self.app(environ, start_response)
File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
raise e
File "/bin/user_wsgi_wrapper.py", line 154, in __call__
app_iterator = self.app(environ, start_response)
File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
raise e
File "/bin/user_wsgi_wrapper.py", line 179, in <module>
application = load_wsgi_application()
File "/bin/user_wsgi_wrapper.py", line 175, in load_wsgi_application
return __import__(os.environ['WSGI_MODULE'], globals(), locals(), ['application']).application
File "/var/www/khalid_pythonanywhere_com_wsgi.py", line 25, in <module>
application = get_wsgi_application()
File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup()
File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named 'endless_pagination'
I installed it using easy_install -Z django-endless-pagination, and added 'django.core.context_processors.request' in the Settings.py context_processors (under TEMPLATES).
I added 'endless_pagination' in the installed apps section of the Settings.py. These are the steps from the documentation, when I reload the server, I get ImportError: No module named 'endless_pagination'. What seems to be the problem here?
Any help/direction would be appreciated,
Thanks
INSTALLATION OUTPUT:
(myvenv) 08:19 ~/mysite $ easy_install -Z django-endless-pagination
Searching for django-endless-pagination
Reading https://pypi.python.org/simple/django-endless-pagination/
Downloading https://pypi.python.org/packages/6e/82/27bac7a83a5aedb45d031edb5a0ce2f0f9c57b81254e4e162a6bbd94acfa/django-
endless-pagination-2.0.tar.gz#md5=8efa40cee51ebe229ce15ed258594ba0
Best match: django-endless-pagination 2.0
Processing django-endless-pagination-2.0.tar.gz
Writing /tmp/easy_install-lsvk24ce/django-endless-pagination-2.0/setup.cfg
Running django-endless-pagination-2.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-lsvk24ce/django-endless-pagina
tion-2.0/egg-dist-tmp-3qtpwgoa
zip_safe flag not set; analyzing archive contents...
creating /home/khalid/mysite/myvenv/lib/python3.5/site-packages/django_endless_pagination-2.0-py3.5.egg
Extracting django_endless_pagination-2.0-py3.5.egg to /home/khalid/mysite/myvenv/lib/python3.5/site-packages
Adding django-endless-pagination 2.0 to easy-install.pth file
Installed /home/khalid/mysite/myvenv/lib/python3.5/site-packages/django_endless_pagination-2.0-py3.5.egg
Processing dependencies for django-endless-pagination
Finished processing dependencies for django-endless-pagination
if you are using Django 1.8 or newer, you must use this one: http://django-el-pagination.readthedocs.io/en/latest/start.html (EL Pagination), endless paginations is deprecated in Django 1.8 and newers
I was running my project using Django 1.8 and it was working properly. But then I had to upgrade Django to 1.9 now when I again run my project it gave an error - ImportError: cannot import name get_cache.
python manage.py syncdb
and I get following:
Traceback (most recent call last):
File "manage.py", line 10, in <module> execute_from_command_line(sys.argv)
File "/home/vermahim17/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350,
in execute_from_command_line utility.execute()
File "/home/vermahim17/env/local/lib/python2.7/site-packages/django/core/management/__init__.py",
line 324, in execute django.setup()
File "/home/vermahim17/env/local/lib/python2.7/site-packages/django/__init__.py",
line 18, in setup apps.populate(settings.INSTALLED_APPS)
File "/home/vermahim17/env/local/lib/python2.7/site-packages/django/apps/registry.py",
line 85, in populate app_config = AppConfig.create(entry)
File "/home/vermahim17/env/local/lib/python2.7/site-packages/django/apps/config.py",
line 90, in create module = import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py",
line 37, in import_module __import__(name)
File "/home/vermahim17/env/local/lib/python2.7/site-packages/keyedcache/__init__.py",
line 27, in <module>
from django.core.cache import get_cache, InvalidCacheBackendError, DEFAULT_CACHE_ALIAS ImportError: cannot import name get_cache
I think , Django 1.9 doesn't have the provision to import get_cache method. Please look into this to fix
https://github.com/vstoykov/django-imagekit/commit/c26f8a0
Python, Django 1.3.5
I am using virtualenv, sudo pip install PyCrypto==2.6, which succeed.
But Django's error:
Traceback (most recent call last):
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 283, in run
self.result = application(self.environ, self.start_response)
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 272, in __call__
response = self.get_response(request)
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 214, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/zhanglei/Develop/medweb/urls.py", line 9, in <module>
from website.views import index, home, login, register, read_verify_code, clinic_problems, \
File "/Users/zhanglei/Develop/medweb/website/views.py", line 13, in <module>
from api.views import alipay_data_process
File "/Users/zhanglei/Develop/medweb/api/views.py", line 26, in <module>
from api.alipay import check_with_rsa_ali, parse_notify_data, decrypt_with_rsa_chunyu
File "/Users/zhanglei/Develop/medweb/api/alipay/__init__.py", line 2, in <module>
from Crypto import Signature
ImportError: No module named Crypto
but when i install pycrypto on local env, it can be imported by python.
When you use sudo it runs as root and installs in the system directories. You want to run it as your regular user while you are inside your virtualenv:
source medweb-env/bin/activate
pip install pycrypto==2.6
I am using mod_wsgi and virtualenv and running a django application.
However, it raises and interesting syntax error. Although it is running on my local, it didn't run at server.
SyntaxError: invalid syntax
mod_wsgi (pid=29322): Exception occurred processing WSGI script '/var/www/html/myproject/django.wsgi'.
Traceback (most recent call last):
File "/home/sin/django_projects/webapp/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 272, in __call__
response = self.get_response(request)
File "/home/sin/django_projects/webapp/lib/python2.7/site-packages/django/core/handlers/base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/home/sin/django_projects/webapp/lib/python2.7/site-packages/django/core/handlers/base.py", line 214, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/home/sin/django_projects/webapp/lib/python2.7/site-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/home/sin/django_projects/webapp/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/sin/django_projects/myproject/urls.py", line 8, in ?
admin.autodiscover()
File "/home/sin/django_projects/webapp/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
import_module('%s.admin' % app)
File "/home/sin/django_projects/webapp/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/sin/django_projects/myproject/userprofile/admin.py", line 1, in ?
from myproject.companyreview.models import ReviewRate
File "/home/sin/django_projects/myproject/companyreview/models.py", line 9
class CommentStatus():
SyntaxError: invalid syntax
companyreview model
class CommentStatus():
PENDING = 0
CONFIRMED = 1
DELETED = 2
django.wsgi
import os
import sys
import site
vepath = '/home/sin/django_projects/webapp/lib/python2.7/site-packages'
site.addsitedir(vepath)
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
sys.path.append('/home/sin/django_projects/')
sys.path.append('/home/sin/django_projects/myproject/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I suspect the python versions because if there were a syntax error, it won't run in local. What may cause such a silly error?
Thanks
Versions of Python older than 2.5 do not accept an empty base list. Either derive from object or remove the parens.
class CommentStatus(object):