"错误": ["由于 I/O 错误,无法将输入流解析为 JSON 文档:解析错误:预期的'}',但看到'","' [ 字符读取 = *****]



我正在尝试以编程方式创建缺陷。我遇到了一些错误,并且无法进一步。从本质上讲,这是代码:

import requests, json
rally_auth = ('**uid', '***pwd')
rally_auth_url = 'https://rally1.rallydev.com/slm/webservice/v2.0/security/authorize'
rally_defect = 'https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement'
workspace_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/workspace/123***'
fe_project_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/project/134***'                           
user_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/user/106***'
l2_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/l2roadmapitem/166***'
headers = {"Accept": "application/json", "Content-Type": "application/json", "ZSESSIONID" : "_iv********"}
s = requests.Session()
token = '_iv**********'
url = rally_defect + '/create?key=' + token
payload = {
'Workspace' : workspace_ref,
'Name': 'Tesing',
'Description': 'Testing',
'Project': fe_project_ref,
'StoryType': "New Feature", 
'PortfolioItem' : l2_ref,
'Owner' : user_ref,
'ScheduleState':'Defined',
}
r = s.put(url, data=json.dumps(payload), headers=headers)
print r.text
print r.status_code
{"CreateResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "错误": [">

由于 I/O 错误,无法将输入流解析为 JSON 文档: 解析错误: 预期的'}' 但看到 ',' [ 字符读取 = *****], "警告": []}}

您需要在 JSON 中提供项目类型。 下面是应该适合您的代码的更新。 我还假设"故事类型"是一个自定义字符串字段。 您需要将名称更新为"c_StoryType"才能向自定义字段添加值。

我还删除了一些多余的行。 由于您使用的是 API 密钥并将其设置为标头中的 ZSessionID,因此您不需要安全令牌来创建项目。

import requests, json
rally_defect = 'https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement'
workspace_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/workspace/123***'
fe_project_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/project/134***'                           
user_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/user/106***'
l2_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/l2roadmapitem/166***'
headers = {"Accept": "application/json", "Content-Type": "application/json", "ZSESSIONID" : "_iv********"}
s = requests.Session()
url = rally_defect + '/create'
payload = {
"HierarchicalRequirement" : {
"Workspace" : workspace_ref,
"Name" : "Tesing",
"Description" : "Testing",
"Project" : fe_project_ref,
"c_StoryType" : "New Feature",
"PortfolioItem" : l2_ref,
"Owner" : user_ref,
"ScheduleState" : "Defined"
}
}
r = s.put(url, data=json.dumps(payload), headers=headers)
print r.text
print r.status_code

最新更新