3

JSONDecodeError, when use json.loads in Django.

POST data

(b'csrfmiddlewaretoken=ikpUI4vMMbYivTby6FUkXRGNXisF6Cgq5eRnYvqoxRoyfAkwiP5GlsBj' b'jVlh3Va4&pergunta%5B1%5D%5Bitem%5D%5B1%5D=&pergunta%5B1%5D%5Bitem%5D%5B2%5D=' b'&pergunta%5B2%5D%5Bitem%5D%5B3%5D=&pergunta%5B2%5D%5Bitem%5D%5B4%5D=&pergunt' b'a%5B2%5D%5Bitem%5D%5B5%5D=&pergunta%5B2%5D%5Bitem%5D%5B6%5D=')

def post(self, request):

    data = json.loads(request.body)
    pprint(data)
    return HttpResponse(data)

Output Error

JSONDecodeError at /

Request Method: POST Request URL: http://localhost:8000/rma/ Django Version: 1.11.7 Exception Type: JSONDecodeError Exception Value:
Expecting value: line 1 column 1 (char 0) Exception Location: /usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py in raw_decode, line 357 Python Executable: /Users/marcelowanderley/Python-Compare/bin/python Python Version: 3.6.2

marcelo.delta
  • 2,730
  • 5
  • 36
  • 71

1 Answers1

0

as @marcelo.delta said and for me worked also...

request.POST.dict()

Germano
  • 358
  • 1
  • 2
  • 13