如何动态使用 Jira Python 的用户输入

问题描述

所以我正在尝试制作一种基于 Jira Key 提取 Jira 信息的交互式方法

完整代码

import os
from atlassian import Jira

import json
with open('secrets.json','r') as f:
      config = json.load(f)

jira_instance = Jira(
    url = "https://mirantis.jira.com",username = (config['user']['username']),password = (config['user']['password'])
)

projects = jira_instance.get_all_projects(included_archived=None)

value = input("Please enter your Jira Key and the Issue ID:\n")
jira_key = (value)

issue = jira_instance.issue('(jira_key)',fields='summary,history,created,updated')
#issue = jira_instance.issue('DESDI-212',updated')
print(issue)

最重要的是:

issue = jira_instance.issue('(jira_key)',updated')

出于某种奇怪的原因,它不喜欢我使用用户输入 jira_key 的方式,即使我使用 print(jira_key) 时它会打印出我想要的内容

调用错了吗?

我基本上需要这个:

issue = jira_instance.issue('DESDI-212',updated')

由此,DESDI-212 将是用户输入。 当我尝试使用 '(jira_key)' 时,它会返回以下错误

 rbarrett@MacBook-Pro-2  ~/Projects/Mirantis/Dataeng/Python  python test_single.py                                                             ✔  10422  22:03:34
Please enter your Jira Key and the Issue ID:
DESDI-212
Traceback (most recent call last):
  File "/Users/rbarrett/Projects/Mirantis/Dataeng/Python/test_single.py",line 19,in <module>
    issue = jira_instance.issue('(jira_key)',updated')
  File "/usr/local/lib/python3.9/site-packages/atlassian/jira.py",line 676,in issue
    return self.get("rest/api/2/issue/{0}?fields={1}".format(key,fields),params=params)
  File "/usr/local/lib/python3.9/site-packages/atlassian/rest_client.py",line 264,in get
    response = self.request(
  File "/usr/local/lib/python3.9/site-packages/atlassian/rest_client.py",line 236,in request
    self.raise_for_status(response)
  File "/usr/local/lib/python3.9/site-packages/atlassian/jira.py",line 3715,in raise_for_status
    raise HTTPError(error_msg,response=response)
requests.exceptions.HTTPError: Issue does not exist or you do not have permission to see it.

我希望看到这一点,如果我使用 'DESDI-212' 而不是 '(jira_key)' 它确实有效:

{'expand': 'renderedFields,names,schema,operations,editMeta,changelog,versionedRepresentations','id': '372744','self': 'https://mirantis.jira.com/rest/api/2/issue/372744','key': 'DESDI-212','fields': {'summary': 'Add the MSR version to be parsed into Loadstone','updated': '2021-06-23T17:33:21.206-0700','created': '2021-06-01T12:54:06.136-0700'}}

解决方法

所以事实证明我调用它是错误的。 我需要将 '' 放在 '(jira_key)' 周围,然后使用 (jira_key) 调用它,如下所示:

import os
from atlassian import Jira

import json
with open('secrets.json','r') as f:
      config = json.load(f)

jira_instance = Jira(
    url = "https://mirantis.jira.com",username = (config['user']['username']),password = (config['user']['password'])
)

projects = jira_instance.get_all_projects(included_archived=None)

value = input("Please enter your Jira Key and the Issue ID:\n")
jira_key = (value)

issue = jira_instance.issue((jira_key),fields='summary,history,created,updated')
#issue = jira_instance.issue('DESDI-212',updated')
print(issue)

因此,我得到了我需要的预期输出,但没有按预期工作:

 rbarrett@MacBook-Pro-2  ~/Projects/Mirantis/Dataeng/Python  python test_single.py                                                             ✔  10428  22:22:17
Please enter your Jira Key and the Issue ID:
DESDI-212
{'expand': 'renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations','id': '372744','self': 'https://mirantis.jira.com/rest/api/2/issue/372744','key': 'DESDI-212','fields': {'summary': 'Add the MSR version to be parsed into Loadstone','updated': '2021-06-23T17:33:21.206-0700','created': '2021-06-01T12:54:06.136-0700'}}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...