KeyError:通过Python提交JIra票证的“项目”

时间:2019-05-15 19:42:44

标签: python jira

我正在尝试使用Python自动生成Jira票证。运行脚本,我不断得到追溯。

我正在使用Python 3.6和3.7(我的IDE指向3.7)在Ubuntu Linux上运行它。我已经在网上广泛搜索了解决方案,但没有找到解决方案。

def ticketBody(sprint, uid, [[other stuff]]):
    return({
        "fields": {
           "project": {"key": "DEV"},
           "summary": "Search Term: " + uid,
           "description": "Some Description",
           "issuetype": {"name": "Bug"},
           "Epic Link": "DEV-1",
           "Sprint": sprint,
           "assignee": "awesomeEngr",
        }
    })

BODY = ticketBody(sprint,uid,[other_params])
authd.create_issue(fields=BODY)

Traceback (most recent call last):
  File "/home/wsherwin/.../python/dataQuality.py", line 68, in <module>
    main()
  File "/home/wsherwin/.../python/dataQuality.py", line 63, in main
    authd.create_issue(fields=BODY)
  File "/home/wsherwin/python-test/lib/python3.7/site-packages/jira/client.py", line 1095, in create_issue
    p = data['fields']['project']
KeyError: 'project'

authd对象代替了jira对象,我无法弄清楚为什么python / Jira找不到我的项目,因为我已经将它传递了。

我希望此返回0带有一个成功的结论-并提交了一堆票证。

1 个答案:

答案 0 :(得分:0)

不确定,但是我认为您的createBody函数应仅返回字段,而不应返回具有单个条目“ fields”的字典:

def ticketBody(sprint, uid):
    return {
        "project": {"key": "DEV"},
        "summary": "Search Term: " + uid,
        "description": "Some Description",
        "issuetype": {"name": "Bug"},
        "Epic Link": "DEV-1",
        "Sprint": sprint,
        "assignee": "awesomeEngr",
    }

注意:您应该遵循PEP8 style guide并在“ ticket_body”中重命名“ ticketBody”。