python - 如何修复 requests.put 方法,因为它显示状态错误代码 500?
问题描述
我正在尝试将 http 请求从客户端发送到要更新页面的服务器。我尝试使用虚拟 html 代码测试我的 requests.put 方法是否有效,并且确实有效。这是我使用的有效代码。
imports requests
from requests.auth import HTTPBasicAuth
headers = {
'Content-Type': 'application/json',
}
pass_string = "<p>This is the updated text for the new page. Created Automatically through script. Experiment successful.</p>"
data = '{"id":"525424594","type":"page", "title":"Update Status","space":{"key":"CSSFW"},"body":{"storage":{"value":"' + pass_string + '","representation":"storage"}}, "version":{"number":17}}'
response = requests.put('https://confluence.ai.com/rest/api/content/525424594', headers=headers, data=data, auth=HTTPBasicAuth('svc-Automation@ai.com', 'AIengineering1@ai'))
但是,一旦我使用要为我的任务传递的 html 字符串,我就会得到一个错误状态代码 500,说明“内部服务器错误”。这是我的代码:
imports requests
from requests.auth import HTTPBasicAuth
from bs4 import BeautifulSoup
pass_string = "<p><br /></p><table><colgroup><col /><col /><col /><col /><col /><col /></colgroup><tbody><tr><th><p>JIRA</p></th><th><p>Type</p></th><th><p>PR</p></th><th><p>Commit</p></th><th><p>Author</p></th><th><p>Date</p></th></tr><tr><td><p>IAP-5742</p></td><td><p>Action-Item</p></td><td><p><br /></p></td><td><p><br /></p></td><td><p><br /></p></td><td><p><br /></p></td></tr><tr><td><p>IAP-5991</p></td><td><p>Action-Item</p></td><td><p><br /></p></td><td><p><br /></p></td><td><p><br /></p></td><td><p><br /></p></td></tr><tr><td><p>IAP-5971</p></td><td><p>Action-Item</p></td><td><p><br /></p></td><td><p><br /></p></td><td><br /></td><td><p><br /></p></td></tr><tr><td><p>IAP-6200</p></td><td><p>Action-Item</p></td><td><p><br /></p></td><td><p><br /></p></td><td><br /></td><td><p><br /></p></td></tr><tr><td><p>IAP-5608</p></td><td><p>Action-Item</p></td><td><p><br /></p></td><td><p><br /></p></td><td><br /></td><td><br /></td></tr><tr><td><p>IAP-5075</p></td><td><p>Action-Item</p></td><td><p><br /></p></td><td><p><br /></p></td><td><br /></td><td><p><br /></p></td></tr><tr><td><p>IAP-5757</p></td><td><p>Bug</p></td><td><p><br /></p></td><td><p><br /></p></td><td><br /></td><td><br /></td></tr></tbody></table><p class=\"auto-cursor-target\"><br /></p>"
headers = {
'Content-Type': 'application/json',
}
data = '{"id":"525424594","type":"page", "title":"Update Status","space":{"key":"CSSFW"},"body":{"storage":{"value":"' + pass_string + '","representation":"storage"}}, "version":{"number":17}}'
response = requests.put('https://confluence.ai.com/rest/api/content/525424594', headers=headers, data=data, auth=HTTPBasicAuth('svc-Automation@ai.com', 'AIengineering1@ai'))
请注意,pass_string 已直接从网站的 rest/api/content 输出中复制,即从https://confluence.ai.com/rest/api/content/525424594?expand=body.storage复制,因此应该字符串没有任何问题,但它仍然显示错误代码 500,我无法理解它为什么会这样做。
解决方案
推荐阅读
- php - 如何将多维数组php中所有id值的子数组计数限制为5?
- python - python的pip install func在我的win系统上不起作用
- javascript - Safari 中不需要的页面重新加载
- mysql - 如果未启用每个文件的 innodb,如何在 mysql 5.6 中查找 innodb 表的数据长度和索引长度
- c++ - 物理子弹 - 任何“幽灵”身体?
- javascript - Google Chrome 扩展:通过 chrome.tabs.executeScript 将注入脚本中的变量暴露给以相同方式注入的另一个脚本
- reactjs - 如何在单击下一步按钮时触发获取以选择下一页
- ascii - 如何使用 SaveData 在 ParaView 3.98.1 中写入 ASCII 文件?
- tensorflow2.0 - 关于tensorflow量子中量子神经网络的输入
- python - 了解 shap.decision_plot