简体   繁体   English

400 Bad Request POST 请求

[英]400 Bad Request POST request

I'm programing in Python some API application, using POSTMAN, and a Bearer token.我正在 Python 一些 API 应用程序中编程,使用 POSTMAN 和 Bearer 令牌。 I already receive the token, and to some GET with success response.我已经收到令牌,并收到一些成功响应的 GET。

But when doing a insert of a record I got 400 Bad request error, this is the code I'm using for adding the record但是在插入记录时出现 400 Bad request 错误,这是我用于添加记录的代码

def add_identity(token, accountid, newIdentity):
    end_point = f"https://identityservice-demo.clearid.io/api/v2/accounts/{accountid}/identities/"
    headers = CaseInsensitiveDict()
    headers["Content-type"] = "application/json; charset=utf-8"
    headers["Authorization"] = f"Bearer {token}"

    response = requests.request("POST", end_point, data=newIdentity, headers=headers)
    print(f"{response.reason} - {response.status_code}")

the variable newIdentity has the following data变量 newIdentity 具有以下数据

nID = {
        "privateData": {
            "birthday": "1985-30-11T18:23:27.955Z",
            "employeeNumber": "99999999",
            "secondaryEmail": "",
            "cityOfResidence": "Wakanda",
            "stateOfResidence": "Florida",
            "zipCode": "102837",
            "phoneNumberPrimary": "(999)-999-999)",
            "phoneNumberSecondary": "+5-(999)-999-9999"
        },
        "companyData": {
            "approvers": [
                {
                    "approverId": ""
                }
            ],
            "supervisorName": "Roger Rabbit",
            "departmentName": "Presidency",
            "jobTitle": "President",
            "siteId": "string",
            "companyName": "ACME Inc",
            "workerTypeDescription": "",
            "workerTypeCode": ""
        },
        "systemData": {
            "hasExtendedTime": "true",
            "activationDateUtc": "2022-03-16T18:23:27.955Z",
            "expirationDateUtc": "2022-03-16T18:23:27.955Z",
            "externalId": "999999",
            "externalSyncTimeUtc": "2022-03-16T18:23:27.955Z",
            "provisioningAttributes": [
                {
                    "name": ""
                }
            ],
            "customFields": [
                {
                    "customFieldType": "string",
                    "customFieldName": "SSNO",
                    "customFieldValue": "9999999"
                }
            ]
        },
        "nationalIdentities": [
            {
                "nationalIdentityNumber": "0914356777",
                "name": "Passport",
                "issuer": "Wakanda"
            }
        ],
        "description": "1st Record ever",
        "status": "Active",
        "firstName": "Bruce",
        "lastName": "Wayne",
        "middleName": "Covid",
        "displayName": "Bruce Wayne",
        "countryCode": "WK",
        "email": "bruce.wayne@wakanda.com",
        "creationOnBehalf": "ACME"
    }

what could solve the problem?什么可以解决问题? the swagger for the API is API 的 swagger 是

https://identityservice-demo.clearid.io/swagger/index.html#/Identities/get_api_v2_accounts__accountId__identities https://identityservice-demo.clearid.io/swagger/index.html#/Identities/get_api_v2_accounts__accountId__identities

Thanks for your help in advance提前感谢您的帮助

data have to be a dict,, you can try import json and data=json.dumps(newIdentity), and if it keeps returning 400, check well that all the parameters are accepted by the api by recreating the request with Postman or any request editor, and if the api uses any web interface check what is the reason for that 400. This was translated by Google so I don't know if I said something nonsense:)数据必须是字典,您可以尝试导入 json 和 data=json.dumps(newIdentity),如果它一直返回 400,请通过使用 Postman 或任何请求重新创建请求来检查 api 是否接受了所有参数editor,如果api使用了web接口,看看是什么原因导致400的。这是谷歌翻译的,不知道我是不是在胡说八道:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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