Friday, December 30, 2016

request.read() is empty in POST

Hello! I'm getting crazy, PLEASE someone, give me some light!!!

I'm using Django 1.10.4, Python 3.5 on Windows using Visual Studio Community 2015.

I have some class-based views to response some json.

from django.views.generic import View
from json import loads
from bson.json_util import dumps
from django.http import HttpResponse, HttpRequest

class Topicos(View):
   
def post(self, request):
       req
= request.read().decode(self.request.encoding)

Have the following setting on urls.py:

url(r'^api/Topicos', Topicos.Topicos.as_view(), name='Topicos'),

The request.read() is empty, the request is: 

POST /api/Topicos HTTP/1.1
Host: localhost:55020
Connection: keep-alive
Content-Length: 93
Accept: application/json, text/plain, */*
Origin:
http://localhost:55020
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
X-CSRFToken: VRiCt3Lz1EIdKGWt3lknpcgdFpD8XbrwSxdPT4P9dd1tbrGYmgE8uHdEIH2dzP5h
Content-Type: application/json;charset=UTF-8
Referer:
http://localhost:55020/
Accept-Encoding: gzip, deflate, br
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: csrftoken=VRiCt3Lz1EIdKGWt3lknpcgdFpD8XbrwSxdPT4P9dd1tbrGYmgE8uHdEIH2dzP5h

{"titulo":"Título 1","mensagem":"mensagem","email":"
flavio@email.test.br","usuario":"Flávio"}


I really don't know what else I can do. I have the same code (except na class name) running correctly to another posts.














--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d754000c-e47b-4cee-bf0a-034ea5ee2e75%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment