使用 Python 的 Zeep 的 SOAP API 请求中缺少元素,但该元素在请求字典中

Missing element in SOAP API request using Python's Zeep, but the element is in the request dictionary

我正在使用 Zeep 与 Workday 的 SOAP 进行交互 API 以编辑某人的 Workday 用户名。以下是对人力资源 WSDL v37.2

的请求正文
    request_dict = {
        "Workday_Account_for_Worker_Update": {
            "Worker_Reference": {
                "Employee_Reference": {
                    "Integration_ID_Reference": {
                        "ID": {
                            "type": "WD-EMPLID",
                            "_value_1": user_id
                        }
                    }
                }
            },
            "Workday_Account_for_Worker_Data": {
                "User_Name": username
            }
        }
    }
    response = client.service.Update_Workday_Account(request_dict)

我收到的错误信息是 zeep.exceptions.ValidationError: Missing element Workday_Account_for_Worker_Data (Workday_Account_for_Worker_Update.Workday_Account_for_Worker_Data),但是元素明明是有的。有人知道我做错了什么吗?

您没有使用正确的方法签名来执行调用。

如果你这样做:

python -mzeep https://community.workday.com/sites/default/files/file-hosting/productionapi/Human_Resources/v37.2/Human_Resources.wsdl > output.txt

然后查看生成的 output.txt 文件,您会看到 Update_Workday_Account 具有此签名:

Update_Workday_Account(
  Worker_Reference: ns0:Worker_ReferenceType,
  Non_Worker_Reference: ns0:RoleObjectType,
  Workday_Account_for_Worker_Data: ns0:Workday_Account_for_Worker_DataType, 
  version: xsd:string, 
  _soapheaders={header: ns0:Workday_Common_HeaderType}
) -> None

所以你的代码应该是这样的:

worker_reference = {
    "Employee_Reference": {
        "Integration_ID_Reference": {
            "ID": {
                "type": "WD-EMPLID",
                "_value_1": user_id
            }
        }
    }
}

workday_account_for_worker_data = {
    "User_Name": username
}

client.service.Update_Workday_Account(worker_reference, None, workday_account_for_worker_data)

我无法真正从我这边测试调用,所以你应该在发出请求之前替换你这边的适当参数。