Python 3.x Redmine API声称失踪';小时数';字段,并在POST to time_entry.json上返回422

Python 3.x Redmine API声称失踪';小时数';字段,并在POST to time_entry.json上返回422,python-3.x,python-requests,redmine,redmine-api,Python 3.x,Python Requests,Redmine,Redmine Api,我正在尝试通过RESTAPI创建一个Redmine 3.3.0.stable安装,使用客户端软件中的。我正在使用以下代码: urlSuffix='/time_entries.json' time_entry = { 'hours': 0.25, 'project_id': 1, 'comments': 'test', 'activity_id': 1, } params = {

我正在尝试通过RESTAPI创建一个Redmine 3.3.0.stable安装,使用客户端软件中的。我正在使用以下代码:

    urlSuffix='/time_entries.json'

    time_entry = {
        'hours':       0.25,
        'project_id':  1,
        'comments':    'test',
        'activity_id': 1,
    }

    params = {
        'key': session.APIKey,
    }

    headers = {
        'Content-Type': 'application/xml',
    }

    requestURL = "%s%s" % (session.redmineBaseUrl, urlSuffix)
    response = requests.post(requestURL, json=time_entry, params=params)
响应。状态\u code
始终为
422
,响应包含以下本地化消息:

{“错误”:[“让人目瞪口呆的人”]}

也就是说

必须提供工作时间

但是,正如您所看到的,字段“hours”给出的是正确的。此外,日志文件表明参数正确到达Redmine:

Started POST "/PROJECTNAMEHERE/time_entries.json?key=APIKEYHERE" for 62.178.175.81 at 2016-11-15 00:19:47 +0100
Processing by TimelogController#create as JSON
  Parameters: {"project_id"=>"1", "spent_on"=>"2016-11-15T00:19:24.513001", "comments"=>"lkj", "activity_id"=>"1", "hours"=>0.25, "key"=>"a009fdb7d15f174b31860cfa9d56fd648737d862"}
  Current user: MichaelJaros (id=5)
  Rendered common/error_messages.api.rsb (0.2ms)
Completed 422 Unprocessable Entity in 22ms (Views: 0.7ms | ActiveRecord: 5.1ms)
我尝试过同样的结果:

  • 本地化小数点的所有组合(
    而不是
  • 以整数、浮点或字符串形式传递小时数
  • 按照建议切换到XML(这也会使Redmine抱怨缺少和无效的项目id)
  • post()
    方法中使用
    data=
    参数而不是
    json=
    (这会使小时值成为类似于
    “1.0”
    的字符串,而不是日志文件中的
    1.0
我最后的办法是尝试其中一种,但我看不出在这种情况下他们应该做什么不同

  • 我做错什么了吗
  • 它们的确切含义是什么:
时间项(必需):时间项属性的散列,包括:[……]


在文档中?当请求是XML格式时,我希望API也需要时间\项的XML数据,而不是“散列”。但也许这部分写得不准确?

我做了一个
pip安装python redmine
,下面的代码工作得很好:

from redmine import Redmine
redmine = Redmine (redmineBaseUrl, version='3.3.0', key=APIKey)
[...]
redmine.time_entry.create(project_id=self.projectId, activity_id=self.activityId, hours=self.getHoursRounded(), spent_on=self.startDateTime.date(), comments=self.comment)

在我昨天花了几个小时胡闹之前,我应该这样做。

我做了一个
pip安装python redmine
,下面的代码工作得非常好:

from redmine import Redmine
redmine = Redmine (redmineBaseUrl, version='3.3.0', key=APIKey)
[...]
redmine.time_entry.create(project_id=self.projectId, activity_id=self.activityId, hours=self.getHoursRounded(), spent_on=self.startDateTime.date(), comments=self.comment)

我应该这样做的,在昨天花了几个小时胡闹之前。

也有同样的问题。用
time\u条目
标记包装时间条目为我解决了问题

发件人:

致:


我也有同样的问题。用
time\u条目
标记包装时间条目为我解决了问题

发件人:

致:

   time_entry = {
        'time_entry': {
             'hours':       0.25,
             'project_id':  1,
             'comments':    'test',
             'activity_id': 1,
        }
    }