How to fix requests.put method as it is showing status error code 500?

694 Views Asked by At

I am trying to send a http request from client to server where I am updating the page. I tried testing if my requests.put method works by using a dummy html code and it does. This is the dummy code I used that works.

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('[email protected]', 'AIengineering1@ai'))

But once I use the html string that I want to pass for my task I get an error status code of 500 stating "Internal Server Error". This is my code:

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('[email protected]', 'AIengineering1@ai'))

Do note that, the pass_string has been copied directly from the rest/api/content ouput of the website i.e from https://confluence.ai.com/rest/api/content/525424594?expand=body.storage and so there should not be anything wrong with the string but still it is showing that error code 500 and I cannot comprehend why it is doing that.

0

There are 0 best solutions below