‘NoneType’ object has no attribute ‘name’ Jira issue type

huangapple go评论91阅读模式
英文:

'NoneType' object has no attribute 'name' Jira issue type

问题

以下是翻译好的部分:

我是新手学习Python我尝试获取Jira数据但在单个问题的`assignee.name`上一直遇到`NoneType`错误我明白为什么会出现这个错误只是不确定如何解决它

columnslist = ['Story', 'Assignee']

data = []

for singleIssue in jira.search_issues(jql_str):
        fields = (
                '{}'.format(singleIssue.key),
                '{}'.format(singleIssue.fields.assignee.name)
                )
        data.append(fields)

dfJira = pd.DataFrame(data, columns=columnslist)

如果需要任何进一步的帮助,请随时告诉我。

英文:

I am new to python. I am trying to pull Jira data and I keep getting a NoneType error on the singleIssue.fields.assignee.name. I understand why I am getting the error, I am just unsure how to resolve it.

columnslist = ['Story', 'Assignee']

data = []

for singleIssue in jira.search_issues(jql_str):
        fields = (
                '{}'.format(singleIssue.key),
                '{}'.format(singleIssue.fields.assignee.name)
                )
        data.append(fields)
    

dfJira = pd.DataFrame(data, columns = columnslist )

答案1

得分: 1

抱歉,你的代码部分包含了许多 HTML 实体编码,我将提供一个翻译清晰的版本如下:

出现 `'NoneType' object has no attribute 'name' Jira issue type` 错误的原因是 Jira 问题没有分配给任何人(**没有受让人**)。您可以在将其添加到 `fields` 元组之前检查问题是否已经被分配。像这样:

columnslist = ['Story', 'Assignee']

data = []

for singleIssue in jira.search_issues(jql_str):
    if singleIssue.fields.assignee is None: # 检查是否未分配受让人
      # 在受让人为 None 的情况下执行所需操作
      fields = (
          '{}'.format(singleIssue.key),
          '未分配'
      )
    else:
      # 在有受让人的情况下执行所需操作
      fields = (
          '{}'.format(singleIssue.key),
          '{}'.format(singleIssue.fields.assignee.name)
      )
    data.append(fields)

dfJira = pd.DataFrame(data, columns=columnslist)
英文:

The reason you are getting the 'NoneType' object has no attribute 'name' Jira issue type error is because the Jira issue has no assignee to it. What you can do is check if the issue has been assigned before adding it to the fields tuple. Like so:

columnslist = ['Story', 'Assignee']

data = []

for singleIssue in jira.search_issues(jql_str):
    if singleIssue.fields.assignee is None: # Check if assignee is None
      # Do what you like in the case that it is None
      fields = (
          '{}'.format(singleIssue.key),
          'No Assignee'
      )
    else:
      # Do what you like in the case that there is an assignee available
      fields = (
          '{}'.format(singleIssue.key),
          '{}'.format(singleIssue.fields.assignee.name)
      )
    data.append(fields)


dfJira = pd.DataFrame(data, columns=columnslist)

huangapple
  • 本文由 发表于 2023年3月21日 02:03:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75793805.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定