Home > Enterprise >  How to solve <Request 400> Error in django?
How to solve <Request 400> Error in django?

Time:04-14

I tried to make a request from my Django project. This is my code:

st_data = {"documentId": 1388,
                       "type": 1,
                       "useAsMain": True
                       }

headers2 = {
                'Authorization': 'Bearer '   token_key,
                "Content-Type": "application/json"

            }

statement = requests.post(url_statement, headers=headers2, data=json.dumps(st_data))

The response of this request is <response 400> And the error code is:

{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-0bbcfce14dfc2146b553c2d98c323b3d-80f72a6fe60f18
4c-00","errors":{"$":["The JSON value could not be converted to System.Collections.Generic.IEnumerable`1[Otc.Data.Objects.StatementDTO]. Path: $ | LineNumber: 0 | BytePositionInLi
ne: 1."]}}

But when I send request from Swagger UI like;

swagger

It returns <response 200>

Where is my mistake?

CodePudding user response:

st_data needs to be a list as it can be seen in Swagger UI example request.

st_data = [{"documentId": 1388,
                   "type": 1,
                   "useAsMain": True
                   }]
  • Related