Why request.body is empty on call custom API using tastypie?

136 Views Asked by At

Facing issue with POST API call. I am using tastypie prepend_urls wrap_view for login custom api.
I am using below versions:
Tastypie 0.14.3
Tastypie_swagger 0.1.4
Django 2.2.12
Python 3.5.2

I am using below deserialize method to abstract data from payload. I don't know why I'm getting empty request.body.

data = self.deserialize(
            request, request.body,
            format=request.META.get('CONTENT_TYPE', 'application/json')
        )

If I'm trying to convert request data into json, Then it is raising Request is not valid JSON. As per my debugging it is using package method named deserialize and into serialize.py of tastypie. It is using from_json method. Also request.body returning blank query dict. I am receiving data which is passing into POST call with request.GET. Is it happening due to upgraded version of python and tastypie? Is there something am I doing wrong?
Here is some output of my request. It would be helpful to understand the scenario.
I am getting this params into GET instead of request.body.

request.GET
<QueryDict: {'username': ['[email protected]'], 'password': ['123456']}>

Empty POST QueryDict

request.POST
<QueryDict: {}>

Request call:

request
<WSGIRequest: POST '/api/v1/user/login/?username=abc%40gmail.com&password=123456'>
self.method_check(request, allowed=['post'])
'post'
request.body
b''

It should have JSON payload like {"username":"password"}. Please suggest me what should I do for resolved below error.

{
  "status": "0",
  "message": "Request is not valid JSON."
}

Thanks in advance!!

0

There are 0 best solutions below