“错误”:[“无法解析由于I / O错误导致的输入流为JSON文档:解析错误:预期'}'但是看到','[chars read = *****]

问题描述 投票:0回答:1

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

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”:{“_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“看到','[chars read = *****],“警告”:[]}}

python post rally
1个回答
0
投票

您需要在JSON中提供Artifact类型。以下是适合您的代码更新。我也假设'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
© www.soinside.com 2019 - 2024. All rights reserved.