[Django]-JSON decode error while sending post request during testing

8πŸ‘

βœ…

The error is coming from signup view at line data = json.loads(data).
In order to access the POST data you can simply access it by using request.POST:

data = request.POST

So remove these lines and replace with above line of code:

data = request.body
data = json.loads(data)

Or try (as figured out via discussion):

response = self.client.post('/signup/', json.dumps(my_data), content_type='application/json')
πŸ‘€Aamir Rind

0πŸ‘

if you get error for printing (using) response.json()
instead of response.json() use response.data

response = self.client.get(url, data)
print(response.json()) # if cause 'json.decoder.JSONDecodeError', use response.data      

0πŸ‘

I was also stuck with it. Use dict() instead of json.

data = dict(request.POST)['checkedbox']
result = list(map(int, data))

Leave a comment