gpt4 book ai didi

python - 带有身份验证的 requests.post 在 python 中为 jira rest api 提供错误 415

转载 作者:行者123 更新时间:2023-12-01 09:46:26 24 4
gpt4 key购买 nike

url = "https://example.com/jira/rest/api/2/issue/issue_key/comment"
data = json.dumps({"body": 'some string'})
headers = {'content-type':'application/json'}
r = requests.post(url, data, auth=('username', 'password'))

--> r.status_code 输出为 415

但万一

r = requests.get(url, data, auth=('username', 'password'))

--> r.status_code 输出为 200。请帮我找出问题。

最佳答案

您忘记将 header 变量添加到您的帖子请求中。这就是它失败的原因。只需将此添加到您的发布请求中,您应该会收到 201 状态代码作为响应:

r = requests.post(url, data, auth=('username', 'password'), headers=headers)

关于python - 带有身份验证的 requests.post 在 python 中为 jira rest api 提供错误 415,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47629594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com