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

huangapple go评论110阅读模式
英文:

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

问题

我有这个Python 3.8的代码
```python
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"}]
             }

_____________________________________
然后我得到了这个错误

创建问题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'

在处理上述异常时发生了另一个异常

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

当我使用我的第二个项目的项目键时,问题被成功创建。
根据JIRA管理员提供的信息,这两个项目具有相同的业务方案和一组必填字段。
字段中的组件也存在。
如果我将错误的组件名称传递给第二个项目,会出现相同的错误。

是什么原因导致了这个错误?我可以检查什么项目/字段设置?

尝试了另一个登录密码 - 失败
尝试了第二个项目 - 成功


<details>
<summary>英文:</summary>
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
</details>
# 答案1
**得分**: 0
我从现有问题中获取字段,如评论中建议的。我传递给请求的项目中组件的名称与实际名称不同。尽管我是从Jira界面中取得的名称。
在界面中是 "Selary"
在现有问题中是 "Selary"
在数据库中是 "Selary"
<details>
<summary>英文:</summary>
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  &quot;Selary&quot;
in existing issue was  &quot; Selary &quot;
in DB was &quot; Selary&quot;
</details>

huangapple
  • 本文由 发表于 2023年3月9日 16:55:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75682320.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定