1

我正在尝试使用客户端软件中的请求库通过 REST API 在 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)

response.status_code总是422,并且响应包含以下本地化消息:

{“错误”:[“Stunden muss ausgefüllt werden”]}

这转化为

必须提供小时数

但是,如您所见,“小时”字段是正确给出的。此外,日志文件表明参数正确到达 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)

我尝试过同样的结果:

  • 本地化小数点的所有组合(,而不是.
  • 将小时作为整数、浮点数或字符串传递
  • 按照 Redmine 板中发现的类似问题的建议切换到 XML (这也使 Redmine 抱怨缺少和无效的项目 ID)
  • 使用data=参数而不是json=post()方法中(这使得小时值是一个字符串,"1.0"而不是1.0在日志文件中)

我最后的手段是尝试其中一个Python Redmine 库,但我看不出他们在这种情况下应该做些什么不同。

  • 我做错什么了吗?
  • 它们到底是什么意思:

time_entry(必需):时间条目属性的哈希,包括:[...]

时间条目文档中?当请求是 XML 格式时,我希望 API 也需要 time_entry 的 XML 数据,而不是“哈希”。但也许那部分只是写得不准确?

4

2 回答 2

0

有同样的问题。用time_entry标签包装时间条目为我解决了这个问题。

从:

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

至:

   time_entry = {
        'time_entry': {
             'hours':       0.25,
             'project_id':  1,
             'comments':    'test',
             'activity_id': 1,
        }
    }
于 2020-09-22T08:10:52.487 回答
0

我做了一个pip install 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)

我应该在昨天搞砸几个小时之前这样做。

于 2016-11-15T09:43:19.567 回答