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

使用Python创建Jira工单遇SSL证书验证失败问题求助

问题排查与解决方案

1. 核心SSL证书问题处理

错误提示明确是自签名证书在证书链中导致验证失败,提供两种解决方式:

临时绕过验证(仅测试环境使用)

在requests.post请求中添加verify=False参数,直接禁用证书验证:

response = requests.post(url, headers=headers, data=payload, verify=False)

注意:生产环境禁止使用,会带来安全风险

信任自签名证书(生产环境推荐)

导出Jira服务器的自签名证书为.pem格式文件,在请求中指定证书路径:

response = requests.post(url, headers=headers, data=payload, verify="/path/to/your/jira-cert.pem")

2. 代码其他问题修正

除SSL问题外,代码还有两处关键错误需要调整:

修正API端点URL

创建工单的正确API路径是/rest/api/2/issue,原代码使用根路径会导致404错误:

url = "https://cxscompany.jira.com/rest/api/2/issue"

修正认证方式

Jira Cloud的个人访问令牌(PAT)仅支持Basic Auth认证,需结合登录邮箱使用:

# 替换为你的Jira登录邮箱
EMAIL = "your-login-email@example.com"
auth = HTTPBasicAuth(EMAIL, TOKEN)

# 移除headers中的Authorization字段,改用auth参数传递认证信息
response = requests.post(url, auth=auth, headers=headers, data=payload, verify=False)

原代码使用的Bearer认证不适用于Jira Cloud的个人令牌,这是请求失败的另一潜在原因

完整修正后的代码

from pprint import pprint
import requests
import json
from requests.auth import HTTPBasicAuth

EMAIL = "your-login-email@example.com"
TOKEN = "KAJSF21DKSAH1KJHFSAN912"

url = "https://cxscompany.jira.com/rest/api/2/issue"
headers = {
    "Accept": "application/json",
    "Content-Type": "application/json"
}
payload = json.dumps({
    "fields": {
        "project": {"key": "AUT"},
        "summary": "summary mike",
        "description": "description mike",
        "issuetype": {"name": "Task"}
    }
})

# 测试环境用verify=False,生产环境替换为证书路径
response = requests.post(url, auth=HTTPBasicAuth(EMAIL, TOKEN), headers=headers, data=payload, verify=False)

pprint(response.json())

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 08:25:19