Jira使用python创建问题

时间:2018-10-29 09:26:43

标签: python python-jira

我正在尝试使用python创建一个Jira Issue,但是在调用新的issue方法时遇到错误,似乎我缺少了某些东西或未尝试正确的方式,报告频率,报告请求类型和到期时间日期是必填字段。谁能帮我解决这个错误?

jira.exceptions.JIRAError: JiraError HTTP 400 url: https://neomediaworld.atlassian.net/rest/api/2/issue
    text: Field 'report frequency' cannot be set. It is not on the appropriate screen, or unknown., Field 'report request type' cannot be set. It is not on the appropriate screen, or unknown., Field 'due date' cannot be set. It is not on the appropriate screen, or unknown., Field 'market' cannot be set. It is not on the appropriate screen, or unknown.

    response headers = {'X-AUSERNAME': 'Dharmendra.mishra', 'X-AREQUESTID': '675ecad3-1149-4673-b283-d86a55292d01', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Transfer-Encoding': 'chunked', 'X-Seraph-LoginReason': 'OK', 'Strict-Transport-Security': 'max-age=315360000; includeSubDomains; preload', 'ATL-TraceId': '49a1e4174e1f0c65', 'ATL-TCS-Time': 'Cache Hit', 'Server': 'Atlassian Proxy/1.13.6.2', 'Connection': 'close', 'Cache-Control': 'no-cache, no-store, no-transform', 'Date': 'Mon, 29 Oct 2018 08:15:59 GMT', 'Content-Type': 'application/json;charset=UTF-8'}
    response text = {"errorMessages":[],"errors":{"market":"Field 'market' cannot be set. It is not on the appropriate screen, or unknown.","due date":"Field 'due date' cannot be set. It is not on the appropriate screen, or unknown.","report frequency":"Field 'report frequency' cannot be set. It is not on the appropriate screen, or unknown.","report request type":"Field 'report request type' cannot be set. It is not on the appropriate screen, or unknown."}}

代码如下。

from jira import JIRA
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import datetime


class JiraException(Exception):
    pass


class Jira(object):

    def __init__(self, **kwargs):

        self.options = {
            'server': 'https://neomediaworld.atlassian.net',
            'verify': False
        }

        self.client = None

        if len(kwargs) != 2:
            raise JiraException(
                'In order to use this class you need to specify a user and a password as keyword arguments!')
        else:
            if 'username' in kwargs.keys():
                self.username = kwargs['username']
            else:
                raise JiraException('You need to specify a username as keyword argument!')
            if 'password' in kwargs.keys():
                self.password = kwargs['password']
            else:
                raise JiraException('You need to specify a password as keyword argument!')

            try:
                self.client = JIRA(self.options, basic_auth=(self.username, self.password))
            except Exception:
                raise JiraException('Could not connect to the API, invalid username or password!')

    def get_projects(self, raw=False):
        projects = []
        for project in self.client.projects():
            if raw:
                projects.append(project)
            else:
                projects.append({'Name': str(project.key), 'Description': str(project.name)})
        return projects

    def new_issue(self):

        issue_dict = {
            'project': {'key': 'MOS'},
            'issuetype': {'name': 'Reporting'},
            'summary': 'Test',
            'market': 'AUS',
            'report request type': 'Ad hoc',
            'report frequency': 'Monthly',
            'description': 'test',
            'due date': '29/Oct/18'}

        new_issue = self.client.create_issue(fields=issue_dict)

0 个答案:

没有答案