You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Jira REST API创建工单时遇405错误,请求技术排查

Jira API创建工单时出现405 Method Not Allowed错误

问题核心

你遇到的405错误是因为请求的URL路径不正确——当前URL包含了/projects/<MYKEY>,这个路径对应的资源不支持POST方法。

解决方案

创建Jira工单的正确API端点不需要包含项目路径,项目信息已经通过请求体中的fields.project.key指定。修正你的URL:

原错误URL:

url = 'https://<enterprise>jira.<domain>.com/projects/<MYKEY>/rest/api/3/issue'

修正后URL:

url = 'https://<enterprise>jira.<domain>.com/rest/api/3/issue'

修正后的完整代码

from requests.auth import HTTPBasicAuth
import requests

user = '<ID>'
password = '<password>'
# 移除路径中的/projects/<MYKEY>
url = 'https://<enterprise>jira.<domain>.com/rest/api/3/issue'


headers = {
    'Content-Type': 'application/json',
}

json_data = {
    
  "fields": {
    "project": {
      "key": "<MYKEY>"
    },
    "summary": "Creating From Collection",
    "description": {
      "type": "doc",
      "version": 1,
      "content": [
        {
          "type": "paragraph",
          "content": [
            {
              "type": "text",
              "text": "This is an autogenerated issue from a demo."
            }
          ]
        }
      ]
    },
    "issuetype": {
      "name": "Task"
    }
  }

}

response = requests.post(
    url,
    headers=headers,
    json=json_data,
    verify=False,
    auth=(user, password),
)

# 可添加调试输出
print(response.status_code)
print(response.text)

额外说明

  • 你已确认手动创建工单的权限正常,所以权限不是问题,核心就是URL路径错误。
  • Jira REST API的创建工单端点是/rest/api/3/issue,项目参数通过请求体传递,无需在URL中指定项目路径。

内容的提问来源于stack exchange,提问作者user14488986

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 10:26:02