使用Python更新JIRA单选按钮字段报Option id 'null'无效错误如何解决
问题根因
- 未正确绑定Jira自定义字段ID:报错和HTML结构显示你要操作的单选字段ID为
customfield_10543,但你代码中的having_pet变量没有被赋值为该字段ID,导致字段没有被正确写入请求参数,接口识别为null值 - 传参格式错误:Jira单选字段支持两种传参格式,你把选项ID塞到了
value参数中,格式不匹配:- 传选项显示文本:
{'value': 'Yes/No'} - 传HTML中抓取的选项ID:
{'id': '10461/10462'}
- 传选项显示文本:
- 缺少兜底逻辑:如果
df.having_pet.iloc[i]的值不是大写的YES/NO(比如出现小写、空值、其他异常值),对应字段不会被赋值,也会触发null报错 - 存在语法错误:构建
new_issue字典时末尾错误使用了右括号),应该使用大括号}
修复后的实现代码
# 先绑定实际的单选字段ID having_pet = "customfield_10543" options = ['10461','10462'] new_issues = [] # 遍历df的逻辑可根据你的实际需求调整 for i in range(len(df)): new_issue = { 'project': {"key":"Test"}, 'summary': 'Test Summary', 'description': 'Test issue by Jira Integration' } # 统一转大写+去空格处理,避免值格式不匹配 current_val = df.having_pet.iloc[i].strip().upper() if current_val == 'YES': new_issue[having_pet] = {'id': options[0]} elif current_val == 'NO': new_issue[having_pet] = {'id': options[1]} else: # 异常值兜底,可根据业务需求调整默认选项,避免传null new_issue[having_pet] = {'id': options[1]} new_issues.append(new_issue) jira.create_issues(field_list=new_issues)
内容的提问来源于stack exchange,提问作者vvazza
相关产品推荐
相关产品推荐

