"Errors": ["Cannot parse input stream due to I/O error as JSON document: Parse error: expected '}' but saw ',' [ chars read = *****]

"Errors": ["Cannot parse input stream due to I/O error as JSON document: Parse error: expected '}' but saw ',' [ chars read = *****]

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

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", "Errors": ["Cannot parse input stream due to I/O error as JSON document: Parse error: expected '}' but saw ',' [ chars read = *****], "警告": []}}

您需要在 JSON 中提供工件类型。以下是对您的代码应该适用的更新。我还假设 'StoryType' 是自定义字符串字段。您需要将名称更新为 'c_StoryType' 才能向自定义字段添加值。

我还删除了一些多余的行。由于您正在使用 API 密钥并将其设置为 Headers 中的 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