无法使用返回错误响应代码 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.JdbcOdbc...