【问题标题】:Python Request Session JIRA REST post http 405Python 请求会话 JIRA REST 发布 http 405
【发布时间】:2018-05-07 17:24:05
【问题描述】:

使用 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 发布有效负载,使用固定的问题 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 等)的多个会话。

【问题讨论】:

    标签: python-requests jira-rest-api


    【解决方案1】:

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

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

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

    2) 为确保有效负载实际呈现为 JSON,请使用 json.dumps(),它接受一个对象并生成一个字符串(请参阅here)并将 'content-type' 设置为'应用程序/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!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 2010-10-29
    • 1970-01-01
    相关资源
    最近更新 更多