简体   繁体   中英

How to solve <Request 400> Error in django?

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;

昂首阔步

It returns <response 200>

Where is my mistake?

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
                   }]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM