get Json data from request with Django
<p>I'm trying to develop a very simple script in Django, I'd collect a Json data from the request and then store all data in the database.</p>

<p>I developed one python script that I'm using to send the Json data to the Django view, but I'm doing something wrong and I can't understand what, because every time that I run it,I've got "Malformed data!".</p>

<p>Can someone helps me? what am I doing wrong?</p>

<p>Sender.py</p>

<pre><code>import json
import urllib2

data = {
         'ids': ["milan", "rome","florence"]
}

req = urllib2.Request('http://127.0.0.1:8000/value/')
req.add_header('Content-Type', 'application/json')

response = urllib2.urlopen(req, json.dumps(data))
</code></pre>

<p>Django view.py</p>

<pre><code>from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse
import json
from models import *

from django.http import StreamingHttpResponse
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def value(request):

  try:
      data = json.loads(request.body)
      label = data['label']
      url = data ['url']
      print label, url
  except:
      return HttpResponse("Malformed data!")
  return HttpResponse("Got json data")
</code></pre>