pycontribs / jira

Python Jira library. Development chat available on https://matrix.to/#/#pycontribs:matrix.org
https://jira.readthedocs.io
BSD 2-Clause "Simplified" License
1.96k stars 873 forks source link

Fail during call create_project function #1334

Open pawelsampolski opened 2 years ago

pawelsampolski commented 2 years ago

Bug summary

When trying to invoke the command _createproject the following exception is received:

{"errorMessages":["Internal server error"],"errors":{}}

Despite the exceptions and the program crash, the project seems to be created correctly

Is there an existing issue for this?

Jira Instance type

Jira Cloud (Hosted by Atlassian)

Jira instance version

No response

jira-python version

3.1.1

Python Interpreter version

3.9.2

Which operating systems have you used?

Reproduction steps

# 1. When I call the function with argument x
jira.create_project('MY', 'MYPROJECT')

Stack trace

r = <Response [500]>, verb = 'POST'
kwargs = {'data': '{"name": "MYPROJECT", "key": "MY", "projectTypeKey": "software", "projectTemplateKey": "com.pyxis.greenhoppe...live', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json', 'X-Atlassian-Token': 'no-check'}, 'json': None}
request = None, error = 'Internal server error', response = {'errorMessages': ['Internal server error'], 'errors': {}}, errorMessages = ['Internal server error']

    def raise_on_error(r: Optional[Response], verb="???", **kwargs):
        """Handle errors from a Jira Request

        Args:
            r (Optional[Response]): Response from Jira request
            verb (Optional[str]): Request type, e.g. POST. Defaults to "???".

        Raises:
            JIRAError: If Response is None
            JIRAError: for unhandled 400 status codes.
            JIRAError: for unhandled 200 status codes.
        """
        request = kwargs.get("request", None)
        # headers = kwargs.get('headers', None)

        if r is None:
            raise JIRAError(None, **kwargs)

        if r.status_code >= 400:
            error = ""
            if r.status_code == 403 and "x-authentication-denied-reason" in r.headers:
                error = r.headers["x-authentication-denied-reason"]
            elif r.text:
                try:
                    response = json.loads(r.text)
                    if "message" in response:
                        # Jira 5.1 errors
                        error = response["message"]
                    elif "errorMessages" in response and len(response["errorMessages"]) > 0:
                        # Jira 5.0.x error messages sometimes come wrapped in this array
                        # Sometimes this is present but empty
                        errorMessages = response["errorMessages"]
                        if isinstance(errorMessages, (list, tuple)):
                            error = errorMessages[0]
                        else:
                            error = errorMessages
                    # Catching only 'errors' that are dict. See https://github.com/pycontribs/jira/issues/350
                    elif (
                        "errors" in response
                        and len(response["errors"]) > 0
                        and isinstance(response["errors"], dict)
                    ):
                        # Jira 6.x error messages are found in this array.
                        error_list = response["errors"].values()
                        error = ", ".join(error_list)
                    else:
                        error = r.text
                except ValueError:
                    error = r.text
>           raise JIRAError(
                error,
                status_code=r.status_code,
                url=r.url,
                request=request,
                response=r,
                **kwargs,
            )
E           jira.exceptions.JIRAError: JiraError HTTP 500 url: https://costy.atlassian.net/rest/api/2/project
E               text: Internal server error
E           
E               response headers = {'Server': 'AtlassianProxy/1.19.3.1', 'cache-control': 'no-cache, no-store, no-transform', 'Content-Type': 'application/json;charset=UTF-8', 'Strict-Transport-Security': 'max-age=315360000; includeSubDomains; preload', 'Date': 'Tue, 15 Mar 2022 13:40:58 GMT', 'ATL-TraceId': '1b9aac75be14aae2', 'x-arequestid': 'b14df56b-3dcf-4c9a-b038-5e1f89ae4f60', 'x-aaccountid': '5f70f073e0e85a006e3123c3', 'X-XSS-Protection': '1; mode=block', 'Transfer-Encoding': 'chunked', 'timing-allow-origin': '*', 'x-envoy-upstream-service-time': '944', 'X-Content-Type-Options': 'nosniff', 'Connection': 'close', 'Expect-CT': 'report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/global-proxy", enforce, max-age=86400'}
E               response text = {"errorMessages":["Internal server error"],"errors":{}}

Expected behaviour

Function should return json with some information about project (fix me if i am wrong)

Additional Context

No response

studioj commented 2 years ago

It seems like the jira server reports an internal server error here. Did you try another project key/name? jira.create_project('MYPROJ', 'My Project')