当前位置: 代码迷 >> python >> 尝试使用PyXero将时间表上传到Xero时的响应405
  详细解决方案

尝试使用PyXero将时间表上传到Xero时的响应405

热度:99   发布时间:2023-06-27 21:48:49.0

库= pyxero 0.9.1

嘿,

我正在尝试使用Python自动将时间表上传到Xero,但遇到了绊脚石。 使用API??检索信息没有问题,但是当我尝试发布新的时间表时,我得到405响应代码。 我尝试将JSON数据简化为Xero所允许的最低限度,但错误仍然存??在。 下面的示例代码

from xero import Xero
import configs
import datetime
from xero.auth import PrivateCredentials
credentials = PrivateCredentials(configss.key, configss.RSAstr)
xero = Xero(credentials)

employees = xero.payrollAPI.employees.all()

timesheets = {'timesheets': {'timesheet': {'EmployeeID': employees[0]["EmployeeID"],
              'StartDate': datetime.datetime(2018,8,15),
              'EndDate': datetime.datetime(2018,8,21),
              'Status': 'Draft'}}}

xero.payrollAPI.timesheets.put(timesheets)

请注意,我可以毫无问题地发布新的联系人和发票。 从app.xero.com网站查看我的API调用历史记录,我看到一条消息,其中包含

请求消息=

    <Timesheets><Timesheet><EmployeeID>38fcaf73-e35c-4f38-9ebe-642ef6d5b7c7</EmployeeID> 
<StartDate>2018-09-15</StartDate><EndDate>2018-09-21</EndDate> 
<Status>DRAFT</Status></Timesheet></Timesheets>

响应405-不允许的方法

您的描述为POST,但代码为“ put”-文档-https: 建议使用的方法为POST。

如果将代码切换为“发布”,是否会达到预期的效果?

  相关解决方案