__init __()在转储中的json / __ init__.py中有一个意外的关键字参数'default'

时间:2013-05-06 17:14:46

标签: python django json tastypie

我有一台运行django的服务器,并且无处不在,我收到了这个错误。我真的不知道是什么变化导致了这一点。

我试图解决这个问题几个小时,但我找不到为什么会发生这种情况。

请给我一些想法。

问我是否需要我的代码的特定部分。虽然Python Path没有提到我的任何文件..

Bug python

完整追溯:

Environment:


Request Method: GET
Request URL: http://whimbee-django.alwaysdata.net/api/v2/eventchat/?format=json

Django Version: 1.4.1
Python Version: 2.6.6
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'tastypie',
 'core',
 'iospush')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'core.middleware.XsSharing')


Traceback:
File "/usr/local/alwaysdata/python/django/1.4.1/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/alwaysdata/python/django/1.4.1/django/views/decorators/csrf.py" in wrapped_view
  77.         return view_func(*args, **kwargs)
File "/home/whimbee-django/modules/django_tastypie-0.9.15-py2.6.egg/tastypie/resources.py" in wrapper
  264.                 return self._handle_500(request, e)
File "/home/whimbee-django/modules/django_tastypie-0.9.15-py2.6.egg/tastypie/resources.py" in _handle_500
  286.             return self.error_response(request, data, response_class=response_class)
File "/home/whimbee-django/modules/django_tastypie-0.9.15-py2.6.egg/tastypie/resources.py" in error_response
  1243.             serialized = self.serialize(request, errors, desired_format)
File "/home/whimbee-django/modules/django_tastypie-0.9.15-py2.6.egg/tastypie/resources.py" in serialize
  397.         return self._meta.serializer.serialize(data, format, options)
File "/home/whimbee-django/modules/django_tastypie-0.9.15-py2.6.egg/tastypie/serializers.py" in serialize
  187.         serialized = getattr(self, "to_%s" % desired_format)(bundle, options)
File "/home/whimbee-django/modules/django_tastypie-0.9.15-py2.6.egg/tastypie/serializers.py" in to_json
  356.             return simplejson.dumps(data, cls=json.DjangoJSONEncoder, sort_keys=True, ensure_ascii=False)
File "/usr/languages/python/2.6/lib/python2.6/json/__init__.py" in dumps
  237.         **kw).encode(obj)

Exception Type: TypeError at /api/v2/eventchat/
Exception Value: __init__() got an unexpected keyword argument 'default'

1 个答案:

答案 0 :(得分:0)

通过快速查看json代码,似乎是使用关键字cls()调用default。默认情况下,cls=JSONEncoder,但在这种情况下,采用json.DjangoJSONEncoder关键字的django_tastypie(在default中定义)似乎不符合隐含要求

来自文档:

  

使用自定义JSONEncoder子类(例如覆盖   序列化其他类型的.default()方法),用它指定   cls kwarg;否则使用JSONEncoder

也许您应该尝试升级到最新版本的tastypie,和/或报告错误。