python调用jira接口示例
时间: 2023-09-06 13:11:57 浏览: 208
jira-python-0.16.tar.gz
以下是一个简单的Python调用JIRA API的示例:
```python
import requests
import json
# JIRA API相关信息
url = 'https://your-jira-url.atlassian.net/rest/api/2/search'
username = 'your-username'
password = 'your-api-token'
# 构建JQL查询语句
jql = 'project = YOURPROJECT'
# 构建请求头
headers = {
'Content-Type': 'application/json'
}
# 构建请求体
data = {
'jql': jql,
'startAt': 0,
'maxResults': 10,
'fields': [
'summary',
'status',
'assignee'
]
}
# 发送请求并获取响应
response = requests.post(
url,
headers=headers,
auth=(username, password),
data=json.dumps(data)
)
# 解析响应
if response.status_code == 200:
issues = json.loads(response.text)['issues']
for issue in issues:
print(issue['fields']['summary'], issue['fields']['status']['name'], issue['fields']['assignee']['displayName'])
else:
print(response.text)
```
这个示例使用requests库发送POST请求,并传递JQL查询字符串、请求头、请求体和认证信息。然后解析响应并输出结果。请注意,您需要将`your-jira-url`、`your-username`和`your-api-token`替换为您自己的信息。
阅读全文