django 1.3 server error - django

I am using django version 1.3. Python manage.py runserver 0.0.0.0:8000 gives the following error.
Validating models...
Unhandled exception in thread started by < bound method Command.inner_run of < django.contrib.staticfiles.management.commands.runserver.Command object at 0x20eb110>>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_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/tastypie/models.py", line 6, in <module>
from tastypie.utils import now
File "/usr/local/lib/python2.7/dist-packages/tastypie/utils/__init__.py", line 1, in <module>
from tastypie.utils.dict import dict_strip_unicode_keys
File "/usr/local/lib/python2.7/dist-packages/tastypie/utils/dict.py", line 1, in <module>
from django.utils.encoding import smart_bytes
ImportError: cannot import name smart_bytes

Its working fine with django 1.4.2+, I was using django1.4 then upgraded it
pip install django==1.4.5 --upgrade

Django 1.3 had the issues of smart_bytes, and from your traceback it shows the same error, its been resolved in Django 1.4, Try upgrading Django to the latest version of 1.5.

See https://github.com/django/django/blob/master/django/utils/encoding.py#L149
Also, always check the release notes before upgrading your Django.
Update:
Sorry about that, wow, what a brainfart ;).
I don't know the full history of that function, but looking at django.utils.encoding on Github.. tagged 1.3.7; this file does not contain the function that Tastypie is attempting to import. https://github.com/django/django/blob/1.3.7/django/utils/encoding.py
If you cannot upgrade Django, you'll need to patch your Tastypie.utils.dict file to work with what you have.

Related

django inplaceedit testing project

New to django… Since a month i'm trying to follow this tutorial without success. When i syncdb i get following error:
(virt-inplaceedit)Mac:testing manuelstrasser$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/manuelstrasser/Desktop/inplace/virt-inplaceedit/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/manuelstrasser/Desktop/inplace/virt-inplaceedit/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/manuelstrasser/Desktop/inplace/virt-inplaceedit/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/manuelstrasser/Desktop/inplace/virt-inplaceedit/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/manuelstrasser/Desktop/inplace/virt-inplaceedit/lib/python2.7/site-packages/django/apps/config.py", line 123, in create
import_module(entry)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/manuelstrasser/Desktop/inplace/virt-inplaceedit/lib/python2.7/site-packages/sorl/thumbnail/__init__.py", line 1, in <module>
from sorl.thumbnail.fields import ImageField
File "/Users/manuelstrasser/Desktop/inplace/virt-inplaceedit/lib/python2.7/site-packages/sorl/thumbnail/fields.py", line 6, in <module>
from sorl.thumbnail import default
File "/Users/manuelstrasser/Desktop/inplace/virt-inplaceedit/lib/python2.7/site-packages/sorl/thumbnail/default.py", line 3, in <module>
from sorl.thumbnail.helpers import get_module_class
File "/Users/manuelstrasser/Desktop/inplace/virt-inplaceedit/lib/python2.7/site-packages/sorl/thumbnail/helpers.py", line 5, in <module>
from django.utils import simplejson
ImportError: cannot import name simplejson
I installed simplejson but still same error. Anyone haveing experiences with this tutorial? I did everything exactly as per description…
django.utils.simplejson is deprecated in django 1.7.
Looks like you use old version of the sorl-thumbnail. Current version of sorl-thumbnail supports django 1.7 so try to update this library.

Django server can not run, why?

E:\pythonwebproject\pythonweb>python manage.py runserver
Validating models...
Unhandled exception in thread started by <function wrapper at 0x01DE69F0>
Traceback (most recent call last):
File "C:\Python26\Lib\site-packages\django\utils\autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "C:\Python26\Lib\site-packages\django\core\management\commands\runserver.py", line 92, in inner_r
self.validate(display_num_errors=True)
File "C:\Python26\Lib\site-packages\django\core\management\base.py", line 277, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python26\Lib\site-packages\django\core\management\validation.py", line 35, in get_validation_
for (app_name, error) in get_app_errors().items():
File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 166, in get_app_errors
self._populate()
File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 72, in _populate
self.load_app(app_name, True)
File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "C:\Python26\Lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python26\Lib\site-packages\django\contrib\auth\models.py", line 21, in <module>
from django.contrib.contenttypes.models import ContentType
File "C:\Python26\Lib\site-packages\django\contrib\contenttypes\models.py", line 127, in <module>
class ContentType(models.Model):
File "C:\Python26\Lib\site-packages\django\db\models\base.py", line 88, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
TypeError: Error when calling the metaclass bases
__init__() keywords must be strings
This bug report is the only resource I can find with similar symptoms. Are you using django 1.5? Try upgrading your python install to 2.7 and see if that rectifies the issue.
You are using the development version of Django (soon to be 1.5) with Python 2.6. It only works with 2.7 and 3.3. You should either upgrade your Python version, or use the released Django version 1.4.

ImportError: cannot import name MPTTModel

I did the steps at the tutorial " http://django-mptt.github.com/django-mptt/tutorial.html "
but it still give me the import error , I double check the code for the mptt and found the class MPTTMODEL exist in the mptt>model file
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x1ec4710>>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 67, in _populate
self.load_app(app_name)
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/kareemhashem/espace/sharek/core/models.py", line 12, in <module>
from mptt.models import MPTTModel, TreeForeignKey
ImportError: cannot import name MPTTModel
One thing you could try: Go to the console and type: python (to get the python console) and then enter: from mptt.models import MPTTModel
If this gives you an error than mptt is not correctly installed.
If you are using pip you could easily do: pip install django-mptt or you might try pip install django-mptt --upgrade to update your installation. It might be that your installation did not succeeded.
If you are not using pip or virtualenv I highly recommend it. The start is a bit tough, but it is worse to install it. See these resources to get started: 1, 2
If you have successfully installed mptt and you still cannot import it, the folder where you placed mptt into is probably not accessible to python. Therefore add the path where mptt lives to your PYTHONPATH. See this thread how to do it.

./manage.py test of Django 1.4 gives a Thing2Literal import not found on google appengine

I followed the steps here https://developers.google.com/cloud-sql/docs/django and it ran well with django 1.3.1. Now up to Django 1.4 and gives a funny stack trace. I would paste the relevant part of the message here
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/dumb906/woody/py/mdlr/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/dumb906/woody/py/mdlr/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/dumb906/woody/py/mdlr/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/dumb906/woody/py/mdlr/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/dumb906/woody/py/mdlr/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/dumb906/woody/py/mdlr/django/core/management/commands/test.py", line 7, in <module>
from django.test.utils import get_runner
File "/home/dumb906/woody/py/mdlr/django/test/__init__.py", line 5, in <module>
from django.test.client import Client, RequestFactory
File "/home/dumb906/woody/py/mdlr/django/test/client.py", line 21, in <module>
from django.test import signals
File "/home/dumb906/woody/py/mdlr/django/test/signals.py", line 2, in <module>
from django.db import connections
File "/home/dumb906/woody/py/mdlr/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/home/dumb906/woody/py/mdlr/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/dumb906/woody/py/mdlr/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/dumb906/woody/py/mdlr/django/db/utils.py", line 44, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'google.appengine.ext.django.backends.rdbms' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: cannot import name Thing2Literal
Any help? Some one said it needs to be compiled http://django-irc-logs.com/2012/mar/27/ ?
I had the same issue. Since the problem is with importing Thing2Literal that is used by adapt_datetime_with_timezone_support function from django/db/backends/mysql/base.py and according to this:
https://code.djangoproject.com/changeset/17596/django/trunk/django/db/backends/mysql/base.py this is important only to datetime objects that bypass the model layer and are used with raw sql. So i decided it is not important for me and I messed a bit my django/db/backends/mysql/base.py: comment out code that causes trouble (import of Thing2Literal, adapt_datetime_with_timezone_support function and line 83 where the function is called)
Of course I upload my django 1.4 customized that way to appengine together with my project and it works.
I would appreciate feedback from those who understand django internals better, whether what i've done is ok assuming i don't use raw sql at all.
As you can see in the documentation you've linked, Google App Engine support only Django up to version 1.3 (actually 1.3.1).

Cannot connect to Oracle database with Django on Ubuntu

Whenever I try to run a command like python manage.py syncdb, I get the following error:
Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/south/management/commands/__init__.py", line 10, in
import django.template.loaders.app_directories
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/template/loaders/app_directories.py", line 21, in
mod = import_module(app)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/contrib/admin/__init__.py", line 1, in
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/contrib/admin/helpers.py", line 1, in
from django import forms
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/forms/__init__.py", line 17, in
from models import *
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/forms/models.py", line 6, in
from django.db import connections
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/__init__.py", line 77, in
connection = connections[DEFAULT_DB_ALIAS]
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/utils.py", line 91, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/utils.py", line 32, in load_backend
return import_module('.base', backend_name)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/damon/Workspace/django-projects/acm-cie/env/lib/python2.6/site-packages/django/db/backends/oracle/base.py", line 24, in
raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading cx_Oracle module: libclntsh.so.11.1: cannot open shared object file: No such file or directory
Is this resolvable on Ubuntu?
You need to install both cx_Oracle and an Oracle Client.
cx_Oracle can be found here.
An appropriate Oracle Client can be found here.
You will also need to set the LD_LIBRARY_PATH variable before you start your application. This can usually be done (for example):
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
Now you should be able to get past the cx_Oracle error message.
First things first - is this actually a Django problem, or just a cx_Oracle problem? Is cx_Oracle installed correctly? Can you connect to your Oracle database in a Python shell session?
import cx_Oracle
conn = cx_Oracle.connect('/') # user/password#dsn
cursor = conn.cursor()
If this doesn't raise an exception, you have connected successfully.
try easy_install cx_Oracle, it will compile cx_Oracle module from source