Python 请求会话 JIRA REST post http 405

Python Request Session JIRA REST post http 405

使用 python 请求会话我可以连接到 JIRA 并检索问题信息...

session = requests.Session()
headers = {"Authorization": "Basic %s" % bas64_val}
session.post(jira_rest_url, headers=headers)
jira = session.get(jira_srch_issue_url + select_fields)

# select_fields = the fields I want from the issue

现在我正在尝试通过 JIRA API post 一个有效负载,使用一个固定的问题 url 例如“https://my_jira_server.com:1234/rest/api/latest/issue/KEY-9876

这应该是以下情况,给定:https://developer.atlassian.com/jiradev/jira-apis/about-the-jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-edit-issues

payload = { "update": {
    "fixVersions": [ {"set": "release-2.139.0"} ]
}}
posted = session.post(jira_task_url, data=payload)

# returns <Response [405]>
# jira_task_url = https://my_jira_server.com:1234/rest/api/latest/issue/KEY-9876

但这似乎不起作用!查看 http 405 响应,表明我的负载格式不正确!值得注意的是,这是最不容易诊断的事情。

我在这里做错了什么?如有任何帮助,我们将不胜感激。

请注意,我 想使用 python jira 模块,我正在使用 requests.session 来管理不同系统的多个会话,即 JIRA , TeamCity 等..

找到解决方案!我有 两个 问题:

1)实际语法结构应该是:

fix_version = { "update": { "fixVersions": [ {"set" : [{ "name" : "release-2.139.0" }]}]

2) 为了确保有效负载实际呈现为 JSON,使用 json.dumps() 获取一个对象并生成一个字符串(参见 ) 并将 'content-type' 设置为 'application/json':

payload = json.dumps(fix_version)
app_json = { 'content-type': 'application/json' }
session.put(https://.../rest/api/latest/issue/KEY-9876, headers=app_json, data=payload)

而不是尝试手动定义 JSON!