Python 3.x Redmine API声称失踪';小时数';字段,并在POST to time_entry.json上返回422
我正在尝试通过RESTAPI创建一个Redmine 3.3.0.stable安装,使用客户端软件中的。我正在使用以下代码: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 = {
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,
}
}