微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法使用返回错误响应代码 400 的 python 请求更新网页

如何解决无法使用返回错误响应代码 400 的 python 请求更新网页

我正在尝试通过 Python requests 模块更新 Atlassian confluence 页面中已经存在的页面。我正在使用 requests.put() 方法发送 HTTP 请求以更新我的页面。该页面已有标题“更新状态”。我试图输入一行作为页面内容。 JSON 有效负载中的页面 ID 和其他信息已由我直接从我尝试访问的网页的 rest/API/content... 输出中复制。注意:我已经可以通过 main 访问网页中的信息,但我无法将信息发布到网页上。

用于从有效网页访问信息的方法

python requests.get

以下是我用来更新返回错误代码 400 的网页的代码

response = requests.get('https://confluence.ai.com/rest/api/content/525424594?expand=body.storage',auth=HTTPBasicAuth('svc-Automation@ai.com','AIengineering1@ai')).json()

result.content 输出以下状态:

import requests
from requests.auth import HTTPBasicAuth
import json

url = "https://confluence.ai.com/rest/api/content/525424594"
payload =  {"id":"525424594","type":"page","title":"new page-Update Status","space":{"key":"TST"},"body":{"storage":{"value": "<p>This is the updated text for the new page</p>","representation":"storage"}},"version":{"number":2}}

result = requests.put(url,json=payload,'AIengineering1@ai'))
print (result.content)

当我转到链接 https://confluence.ai.com/rest/api/content/525424594?expand=body.storage 时,我将页面的其余 api 内容设为:

{"statusCode":400,"data":{"authorized":true,"valid":false,"allowedInReadOnlyMode":true,"errors can't change an existing page's space.","args":[]}}],"successful":false},"message":"Could not update content of type : class com.atlassian.confluence.pages.Page with id 525424594","reason": "Bad Request"} 

以上是我在此页面未更新时在 chrome 上获得的输出。但我想更新它的内容,即它的存储。 我猜我现在使用的有效负载的格式不正确。有什么建议么?注意:此处显示链接用户名和密码均为虚构。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?