有关问题链接的Jira Python Keyerror

时间:2018-11-29 15:14:55

标签: python-3.x jira-rest-api keyerror

我有一个脚本,该脚本将通过Jira API获取信息,然后进行一些比较,但是出现以下错误:

错误:   “ errorMessage”:“'outwardIssue'”   “ errorType”:“ KeyError”

JSON格式:

“问题链接”:[

{
    "id": "1255",
    "self": "https://jiraurl/rest/api/2/issueLink/0000",
    "type": {
        "id": "10030",
        "name": "Arises ",
        "inward": "gives rise to",
        "outward": "arises from",
        "self": "https://jiraurl/rest/api/2/issueLinkType/0000"
    },
    "outwardIssue": {
        "id": "1251575",
        "key": "temp-511",
        "self": "https://jiraurl/rest/api/2/issue/0000",
        "fields": {
            "summary": "a summary",
            "status": {
                "self": "https://jiraurl/rest/api/2/status/6",
                "description": "test",
                "iconUrl": "",
                "name": "Closed",
                "id": "6",
                "statusCategory": {
                    "self": "https://jiraurl/rest/api/2/statuscategory/3",
                    "id": 3,
                    "key": "done",
                    "colorName": "green",
                    "name": "Done"
                }
            },
            "issuetype": {
                "self": "https://jiraurl/rest/api/2/issuetype/20",
                "id": "20",
                "description": "Problem ",
                "iconUrl": "https://jiraurl/images/icons/issuetypes/documentation.png",
                "name": "Problem",
                "subtask": false
            }
        }
    }
}

]

我们认为问题所在的Python语句:

if(problem ['fields'] ['issuelinks'] [0] ['outwardIssue'])和(problem ['fields'] ['issuelinks'] [0] ['type'] ['outward' ] ==“ arises from”):                     isitanissue = False

我看不出为什么它卡在了“ outwardIssue”上?

1 个答案:

答案 0 :(得分:0)

尝试一下:

issue = jira.issue("XX)

if (issue.raw['fields']['issuelinks'][0]['outwardIssue']) and (issue.raw['fields']['issuelinks'][0]['type']['outward'] == "arises from"): isitanissue = False