2013-08-02 20 views
0

我試圖測試我的API,我從來沒有遇到過這個問題。我收到錯誤:No JSON object could be decoded。我很困難,並會感謝任何幫助。我甚至不知道如何調試它們。沒有JSON對象可以用tastypie解碼

這僅發生在「POST」

這裏是我的API

from reflection.feedback.models import Feedback 
from django.contrib.auth.models import User 
from tastypie import fields 
from tastypie.api import Api 
from tastypie.authentication import Authentication 
from tastypie.authorization import Authorization 
from tastypie.exceptions import NotFound 
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS 

class DjangoAuthentication(Authentication): 
    """Authenticate based upon Django session""" 
    def is_authenticated(self, request, **kwargs): 
     return request.user.is_authenticated() 

class CommonMeta: 
    authentication = DjangoAuthentication() 
    authorization = Authorization() 
    always_return_data = True 

class UserResource(ModelResource): 

    class Meta(CommonMeta): 
     queryset = User.objects.all() 
     resource_name = 'user' 
     excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser'] 
     filtering = { 
      'username': ALL, 
     } 

class FeedbackResource(ModelResource): 

    user = fields.ForeignKey(UserResource, 'user') 

    class Meta(CommonMeta): 
     queryset = Feedback.objects.all() 
     resource_name = 'feedback' 
     excludes = ['created',] 
     allowable_methods = ['post',] 
     filtering = { 
      'user': ALL_WITH_RELATIONS 
     } 

    def obj_create(self, bundle, request=None, **kwargs): 
     return super(FeedbackResource, self).obj_create(bundle, request) 

回答

0

我不認爲這有什麼不對您的Python代碼,如果你使用cURL發出請求在Windows上確保JSON數據用雙引號引起來,並且json中的所有雙引號都用反斜線進行轉義。

相關問題