Django Tastypie:“error_message”:“'bool'对象没有属性'read'”

时间:2013-07-16 09:04:31

标签: django rest backbone.js tastypie

我正在使用 Backbone.js + Tastypie + Django ,并尝试使用patch = true保存模型以更新模型上的点,例如

this.save({
  points: newPoints
}, {
  patch: true
});

这会向请求有效负载发出PUT请求

points: 105

但是,我收到500错误消息

{"error_message": "'bool' object has no attribute 'read'", "traceback": "Traceback (most recent call last):

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/tastypie/resources.py\", line 217, in wrapper
    response = callback(request, *args, **kwargs)

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/tastypie/resources.py\", line 468, in dispatch_detail
    return self.dispatch('detail', request, **kwargs)

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/tastypie/resources.py\", line 491, in dispatch
    response = method(request, **kwargs)

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/tastypie/resources.py\", line 1656, in patch_detail
    self.update_in_place(request, bundle, deserialized)

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/tastypie/resources.py\", line 1679, in update_in_place
    return self.obj_update(bundle=original_bundle, **kwargs)

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/tastypie/resources.py\", line 2209, in obj_update
    bundle = self.full_hydrate(bundle)

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/tastypie/resources.py\", line 909, in full_hydrate
    value = field_object.hydrate(bundle)

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/tastypie/fields.py\", line 382, in hydrate
    value = make_aware(parse(value))

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/dateutil/parser.py\", line 720, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/dateutil/parser.py\", line 308, in parse
    res = self._parse(timestr, **kwargs)

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/dateutil/parser.py\", line 356, in _parse
    l = _timelex.split(timestr)

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/dateutil/parser.py\", line 150, in split
    return list(cls(s))

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/dateutil/parser.py\", line 147, in next
    return self.__next__()  # Python 2.x support

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/dateutil/parser.py\", line 141, in __next__
    token = self.get_token()

  File \"/Users/me/.virtualenvs/project/lib/python2.7/site-packages/dateutil/parser.py\", line 72, in get_token
    nextchar = self.instream.read(1)

AttributeError: 'bool' object has no attribute 'read'
"}

这是我的UserProfile模型资源

class UserProfileResource(ModelResource):

    """A resource for the UserProfile model."""

    class Meta:
        queryset = UserProfile.objects.all()
        resource_name = 'userprofile'
        authorization = Authorization()
        excludes = ['field_to_exclude']
        always_return_data = True

有没有人有关于如何调试此错误的提示?

1 个答案:

答案 0 :(得分:0)

我有一个字段是datetimefield,它是null,而不是在api调用中显示为日期时间,而是显示为布尔值。我不确定为什么会发生这种情况,但我认为这是tastypie中的一个错误,或者我误解了配置,或者两者兼而有之。

我从tastypie资源中排除了这个字段,我能够成功地将PUT和PATCH传递给模型。