title: Python/Django with REST Framework - Error on POST {"non_field_errors": ["Invalid data"]}
body: <p>I'm just starting out with Django and the <a href="http://www.django-rest-framework.org/" rel="nofollow">REST Framework</a> and I'm getting an error when trying to POST an entity. There error is: <strong>{"non_field_errors": ["Invalid data"]}</strong>. This happens at the line <strong>serializer.is_valid()</strong></p>
  
  <p>This is is what my view class looks like:</p>
  
  <pre><code>from django.http import HttpResponse
  from django.views.decorators.csrf import csrf_exempt
  from rest_framework.renderers import JSONRenderer
  from rest_framework.parsers import JSONParser
  from API.models import Payload
  from API.serializers import PayloadSerializer
  from API.services import PayloadService
  
  
  class JSONResponse(HttpResponse):
      """
      An HttpResponse that renders its content into JSON.
      """
  
      def __init__(self, data, **kwargs):
          content = JSONRenderer().render(data)
          kwargs['content_type'] = 'application/json'
          super(JSONResponse, self).__init__(content, **kwargs)
  
  
      @csrf_exempt
      def payload_list(request):
  
  
          if request.method == 'POST':
  
              model = Payload(code="754d", body="Hello World")
  
              serializer = PayloadSerializer(data=model)
  
              if serializer.is_valid():
                  serializer.save()
                  return JSONResponse(serializer.data, status=201)
      return JSONResponse(serializer.errors, status=400)
  </code></pre>
  
  <p>Here is my Payload model for reference:</p>
  
  <pre><code>from __future__ import unicode_literals
  from sqlserver_ado.fields import BigAutoField
  from django.db import models
  
  
  class Payload(models.Model):
      id = BigAutoField(db_column='Id', primary_key=True) # Field name made lowercase.
      code = models.CharField(db_column='Code', max_length=10) # Field name made lowercase.
      body = models.TextField(db_column='Body') # Field name made lowercase.
      class Meta:
          managed = False
          db_table = 'Payload'
  </code></pre>
  
  <hr>
  
  <hr>
  
  <p>It's worth noting that if I set up my view properly and actually pass in a Json Payload object as part of the request, it works fine.</p>
  
  <p>Working JSON payload: <code>{"code": "NPMC", "body": "Hello World"}</code></p>
  
  <p>Working view code:</p>
  
  <pre><code>if request.method == 'POST':
  
      data = JSONParser().parse(request)
  
      serializer = PayloadSerializer(data=data)
  
      if serializer.is_valid():
          serializer.save()
          return JSONResponse(serializer.data, status=201)
      return JSONResponse(serializer.errors, status=400)
  </code></pre>
  
  <p>Response: <code>{"id": 25, "code": "NPMC", "body": "Hello World"}</code></p>