使用python连接本地化的jira服务,不需要api密钥,只需要jira的账号密码就可以了
python
import requests
from requests.auth import HTTPBasicAuth
import json
# Jira Server 地址
jira_url = "http://jira.hendp.com/rest/api/2/search"
# Jira 用户名和密码(请替换为你的用户名和密码)
username = "xx"
password = "xxx"
# 设置请求头
headers = {
"Accept": "application/json"
}
# 查询参数(JQL查询)
query = {
'jql': 'issuetype = "xx" AND labels = "xx"', # 使用精确匹配标签
'maxResults': 200, # 返回的最大结果数量
'fields': '*navigable' # 返回的字段(全部或特定字段)
}
if __name__ == '__main__':
# 发送请求
response = requests.get(
jira_url,
headers=headers,
params=query,
auth=HTTPBasicAuth(username, password) # 使用Basic Authentication
)
# 处理响应
if response.status_code == 200:
issues = response.json().get('issues')
print(json.dumps(issues, indent=4)) # 打印返回的JSON数据格式化输出
else:
print(f"Failed to fetch data: {response.status_code} {response.text}")