Python requests Post request data with Django

django, python

Solution

The `POST` dictionary only contains the form-encoded data that was sent in the body of the request. The `body` attribute contains the raw body of the request as a string. Since you are sending json-encoded data it only shows up in the raw `body` attribute and not in `POST`.

Check out more info in the docs.

Try form-encoded data and you should see the values in the `POST` dict as well:

payload = {'test':'test'}
url = "localhost:8000"
requests.post(url, data=payload)

Problem

I'm trying to send a simple post request to a very simple django server and can't wrap my head around why the post data isn't appearing in the requests post dictionary and instead its in the request body. Client code: ``` payload = {'test':'test'} headers = {'Content-type': 'application/json','Accept': 'text/plain'} url = "localhost:8000" print json.dumps(payload) r = requests.post(url,data=json.dumps(payload),headers=headers) ``` Server Code: ``` def submit_test(request): if request.method == 'POST': print 'Post: "%s"' % request.POST print 'Body: "%s"' % request.body return HttpResponse('') ``` What is printed out on the server is: ``` Post: "<QueryDict: {}>" Body: "{"test": "test"}" ``` I've played around with the headers and sending the data as a straight dictionary and nothing seems to work. Any ideas? Thanks!!

Original source