Search code examples
pythonjira

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


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:\Users\Max\PycharmProjects\GSheets-Test\venv\lib\site-packages\atlassian\rest_client.py", line 436, in raise_for_status
    j.get("errorMessages", list()) + [k.get("message", "") for k in j.get("errors", dict())]
  File "C:\Users\Max\PycharmProjects\GSheets-Test\venv\lib\site-packages\atlassian\rest_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:\Users\Max\PycharmProjects\GSheets-Test\test.py", line 37, in <module>
    print(jira.issue_create(fields_arl))
  File "C:\Users\Max\PycharmProjects\GSheets-Test\venv\lib\site-packages\atlassian\jira.py", line 1402, in issue_create
    return self.post(url, data={"fields": fields})
  File "C:\Users\Max\PycharmProjects\GSheets-Test\venv\lib\site-packages\atlassian\rest_client.py", line 333, in post
    response = self.request(
  File "C:\Users\Max\PycharmProjects\GSheets-Test\venv\lib\site-packages\atlassian\rest_client.py", line 257, in request
    self.raise_for_status(response)
  File "C:\Users\Max\PycharmProjects\GSheets-Test\venv\lib\site-packages\atlassian\rest_client.py", line 440, in raise_for_status
    response.raise_for_status()
  File "C:\Users\Max\PycharmProjects\GSheets-Test\venv\lib\site-packages\requests\models.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


Solution

  • 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"