I'm using the python django framework for a web app on an Ubuntu Virtual Machine. I have run the app before on another virtual machine and it worked perfectly. I think everything is inatalled ok as I can runserver amd collectstatic without any issues.
However, upon pages load I'm give the traceback;
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 72, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 243, in __call__
signals.request_started.send(sender=self.__class__)
File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 170, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 58, in reset_queries
for conn in connections.all():
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 105, in all
return [self[alias] for alias in self]
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 27, in load_backend
return import_module('.base', backend_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/sql_server/pyodbc/base.py", line 31, in <module>
raise ImproperlyConfigured("Django %d.%d is not supported." % DjangoVersion[:2])
ImproperlyConfigured: Django 1.5 is not supported.
[11/Sep/2014 08:56:51] "GET /input_parameters HTTP/1.1" 500 59
Can anybody help me? Thanks
Related
I was working with tweepy with Django and the code was working fine.
But, when I deployed the code on railway (similar to Heroku), the app showed these logs:
File "/app/tweet_scrapper/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/opt/venv/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/opt/venv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/venv/lib/python3.9/site-packages/django/apps/registry.py", line 124, in populate
app_config.ready()
File "/app/tweets/apps.py", line 10, in ready
from . import jobs
File "/app/tweets/jobs.py", line 85, in <module>
scrap()
File "/app/tweets/jobs.py", line 69, in scrap
searched_tweets = api.search_tweets(
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 33, in wrapper
return method(*args, **kwargs)
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 46, in wrapper
return method(*args, **kwargs)
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 1309, in search_tweets
return self.request(
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 263, in request
raise Unauthorized(resp)
tweepy.errors.Unauthorized: 401 Unauthorized
32 - Could not authenticate you.
Traceback (most recent call last):
File "/opt/venv/lib/python3.9/site-packages/gunicorn/arbiter.py", line 502, in spawn_worker
worker.init_process()
File "/opt/venv/lib/python3.9/site-packages/gunicorn/workers/base.py", line 114, in init_process
self.wsgi = self.app.wsgi()
File "/opt/venv/lib/python3.9/site-packages/gunicorn/app/base.py", line 66, in wsgi
self.callable = self.load()
File "/opt/venv/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/opt/venv/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/opt/venv/lib/python3.9/site-packages/gunicorn/util.py", line 356, in import_app
__import__(module)
File "/app/tweet_scrapper/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/opt/venv/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/opt/venv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/venv/lib/python3.9/site-packages/django/apps/registry.py", line 124, in populate
app_config.ready()
File "/app/tweets/apps.py", line 10, in ready
from . import jobs
File "/app/tweets/jobs.py", line 85, in <module>
scrap()
File "/app/tweets/jobs.py", line 69, in scrap
searched_tweets = api.search_tweets(
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 33, in wrapper
return method(*args, **kwargs)
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 46, in wrapper
return method(*args, **kwargs)
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 1309, in search_tweets
return self.request(
File "/opt/venv/lib/python3.9/site-packages/tweepy/api.py", line 263, in request
raise Unauthorized(resp)
tweepy.errors.Unauthorized: 401 Unauthorized
32 - Could not authenticate you.
It was working fine locally.
I have elevated access to Twitter API.
I checked all the keys and tokens, and they're correct (but I'm accessing them from environment variables).
My authentication code is this:
secret_key = os.environ.get('secret_key')
secret_key_api = os.environ.get('secret_key_api')
access_token = os.environ.get('acess_token')
access_token_api = os.environ.get('access_token_api')
auth = tweepy.OAuthHandler(secret_key, secret_key_api)
auth.set_access_token(access_token, access_token_api)
api = tweepy.API(auth)
In case, it is caused by requirements.txt, here are the things I included:
Django==4.0.5
django-environ==0.9.0
asgiref==3.4.1
pytz==2022.5
schedule==1.1.0
tweepy==4.11.0
tzdata==2022.1
urllib3==1.26.9
gunicorn==19.0.0
whitenoise==6.0.0
I hit a problem when run django from command line with manage.py runserver.
The same code is fine with Django 1.5 several months ago.
Today I wanna pickup the code again and run upon Django 1.8.3 and python2.7.10 .
Now, got error here:
Traceback (most recent call last):
File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/media/wni/study/workspace4320151111/weichun/mytheme/models.py", line 8, in <module>
from mezzanine.pages.models import Page
File "/media/wni/study/workspace4320151111/weichun/mezzanine/pages/models.py", line 34, in <module>
class Page(BasePage):
File "/media/wni/study/workspace4320151111/weichun/mezzanine/core/models.py", line 350, in __new__
return super(OrderableBase, cls).__new__(cls, name, bases, attrs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 298, in __new__
new_class.add_to_class(field.name, copy.deepcopy(field))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "/media/wni/study/workspace4320151111/weichun/mezzanine/generic/fields.py", line 226, in contribute_to_class
super(KeywordsField, self).contribute_to_class(cls, name)
File "/media/wni/study/workspace4320151111/weichun/mezzanine/generic/fields.py", line 84, in contribute_to_class
cls._meta.get_fields_with_model()]:
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 56, in wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 432, in get_fields_with_model
return [self._map_model(f) for f in self.get_fields()]
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 740, in get_fields
return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 802, in _get_fields
all_fields = self._relation_tree
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 60, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 709, in _relation_tree
return self._populate_directed_relation_graph()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 681, in _populate_directed_relation_graph
all_models = self.apps.get_models(include_auto_created=True)
File "/usr/local/lib/python2.7/dist-packages/django/utils/lru_cache.py", line 101, in wrapper
result = user_function(*args, **kwds)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 168, in get_models
self.check_models_ready()
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
Anyone knows how to fix it?
Thanks.
Wesley
I think you need to change your wsgi.py file as you go for different version of Django.
import os
import sys
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'YourAppName.settings'
application = WSGIHandler()
And try to comment all third party application imported in settings.py.
1] ./manage.py runserver will use your wsgi.py however it looks like the stack trace you've shown at the top does not include the wsgi file. Therefore the error is occurring before the wsgi file is loaded.
2] This could well be an issue with your Django settings. For example,may in LOGGING a filename in a non-existent directory.
3] or check this
I started a Django project using PostgreSQL and it was working fine after setup, I could add things to the database, view it in admin etc. Being new to Postgres, I thought it would be a good idea to quit the terminal to see if if it would 'auto connect' to the database upon restarting (like SQLite does). However now it throws this error:
Kyle$ python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x10f6e4c08>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Library/Python/2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Library/Python/2.7/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 299, in add_to_class
value.contribute_to_class(cls, name)
File "/Library/Python/2.7/site-packages/django/db/models/options.py", line 263, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 212, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 116, in load_backend
return import_module('%s.base' % backend_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
Unhandled exception in thread started by <function wrapper at 0x10b03bc08>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Library/Python/2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Library/Python/2.7/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 299, in add_to_class
value.contribute_to_class(cls, name)
File "/Library/Python/2.7/site-packages/django/db/models/options.py", line 263, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 212, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 116, in load_backend
return import_module('%s.base' % backend_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
When importing the psycopg2 there is no error and inside the psql shell if I type \c it says I have connected to server 'Kyle' (my server name as specified in my django settings) as User 'Kyle' (also as specified in settings).
NB: Using all the latest releases for everything
I think this is a dependency issue, because I realised I wasn't in my virtual environment (it works when I'm in it).
I have a django project working fine . now i need to add login with session on that project I use mango .
As added in setting.py file
SESSION_ENGINE = 'mango.session'
then it started to give following error:
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 170, in __call__
self.load_middleware()
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 52, in load_middleware
mw_instance = mw_class()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/sessions/middleware.py", line 11, in __init__
engine = import_module(settings.SESSION_ENGINE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/shubham/Music/ekomerz/mango/__init__.py", line 2, in <module>
from pymongo import Connection
ImportError: cannot import name Connection
how I can solve this ?
and is there is any other method should i try for login with session ?
I am installing a python project from github (https://github.com/sunlightlabs/publicmarkup) and I get this error message :
File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 283, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 68, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 273, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 214, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/mbenchoufi/git/publicmarkup/../publicmarkup/urls.py", line 5, in <module>
add_to_builtins('mediasync/templatetags/media')
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 1016, in add_to_builtins
builtins.append(import_library(module))
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 951, in import_library
app_path, taglib = taglib_module.rsplit('.',1)
ValueError: need more than 1 value to unpack
I am a newbie to python, what does this error message means ?
The add_to_builtins call in publicmarkup/urls.py is incorrect, it should probably be:
add_to_builtins('mediasync.templatetags.media')
Python packages are dot-delimited and the author used a path instead.
Later on, the Django framework tries to load the module, and splitting off the last name after the last dot fails as there are no dots in the original call.
It looks like the project you are trying to load is fundamentally broken. It probably will have other errors as well.