Python-使用API更新dict中的值时出错



我正在尝试使用API更新一些数据。

如果是一个简单的字段,我可以成功更新。然而,我试图更新的一些字段是字典,所以我在更新这些字段时遇到了问题。

以下是我的数据:

emp_id, emp_name, pay_data
emp_101, Scott, {'annualSalary': 0.0, 'baseRate': 0.0}

如果我要更新prod_name,我会执行以下

url = "https://api.paylocity.com/api/v2/companies/B123/employees/emp_101/?grant_type=client_credentials&scope=WebLinkAPI&client_id=client_id&client_secret=client_secret"
payload = {'emp_name': 'Kevin'}
headers = {'Authorization': 'Bearer ' + access} 
response = requests.request("PATCH", url, headers=headers, json=payload)

代码运行良好。

但是,如果我需要更新pay_data字段中的任何内容,如下所示,我会得到error code 400

url = "https://api.paylocity.com/api/v2/companies/B123/employees/emp_101/?grant_type=client_credentials&scope=WebLinkAPI&client_id=client_id&client_secret=client_secret"
payload = {'annualSalary': '100.0'}
headers = {'Authorization': 'Bearer ' + access} 
response = requests.request("PATCH", url, headers=headers, json=payload)

我认为应该在basePrice中将字符串转换为整数我的意思是,像这样payload = {'basePrice': 101}从"101"(字符串(到101(整数(

代码:

url = 'www.website.com'
payload = {'basePrice': 101}
headers = {'Authorization': 'Bearer ' + access} 
response = requests.request("PATCH", url, headers=headers, json=payload)

最新更新