"requests.exceptions.HTTPError: 400 Client Error" creating a Jira issue when using the package atlassian

Question:

I have this code on python 3.8:

from atlassian import Jira
jira = Jira(
        url='http://jira.mydomain.com/',
        username='login',
        password='password')
summary = 'Test summary'
description = 'Test description'
current_date = datetime.date.today()
duedate = datetime.datetime.strftime(current_date, "%Y-%m-%d")

fields = {"project": {"key": 'ARL'},
          "summary": summary,
          "description": description,
          "issuetype": {"name": "Task"},
          "duedate": duedate,
          "labels": ["Demo"],
          "components": [{"name": "Selary"}]
             }

_____________________________________
And it return me this error:

Creating issue "Test summary"
Traceback (most recent call last):
  File "C:UsersMaxPycharmProjectsGSheets-Testvenvlibsite-packagesatlassianrest_client.py", line 436, in raise_for_status
    j.get("errorMessages", list()) + [k.get("message", "") for k in j.get("errors", dict())]
  File "C:UsersMaxPycharmProjectsGSheets-Testvenvlibsite-packagesatlassianrest_client.py", line 436, in <listcomp>
    j.get("errorMessages", list()) + [k.get("message", "") for k in j.get("errors", dict())]
AttributeError: 'str' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:UsersMaxPycharmProjectsGSheets-Testtest.py", line 37, in <module>
    print(jira.issue_create(fields_arl))
  File "C:UsersMaxPycharmProjectsGSheets-Testvenvlibsite-packagesatlassianjira.py", line 1402, in issue_create
    return self.post(url, data={"fields": fields})
  File "C:UsersMaxPycharmProjectsGSheets-Testvenvlibsite-packagesatlassianrest_client.py", line 333, in post
    response = self.request(
  File "C:UsersMaxPycharmProjectsGSheets-Testvenvlibsite-packagesatlassianrest_client.py", line 257, in request
    self.raise_for_status(response)
  File "C:UsersMaxPycharmProjectsGSheets-Testvenvlibsite-packagesatlassianrest_client.py", line 440, in raise_for_status
    response.raise_for_status()
  File "C:UsersMaxPycharmProjectsGSheets-Testvenvlibsite-packagesrequestsmodels.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://jira.mydomain.com/rest/api/2/issue

When i use project key from my second project – the issue is being created successfully
According to information from the JIRA administrator these projects have the same business scheme and a set of required fields.
The component in field exists too
Same error rase if I pass an incorrect component name to the second project

what causes the error? What project/field settings can I check?

try another login-password – fail
try second project – successful

Asked By: Max Chupin

||

Answers:

I fetch the fields from the existing issue, as advised in the comments. The name of the component in the project that I passed to the request differs from the actual one. Although I took the name from the Jira UI
in UI was "Selary"
in existing issue was " Selary "
in DB was " Selary"

Answered By: Max Chupin
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.