[Confluence Server] Cannot authenticate with REST APIs

sykes_98 January 23, 2020

I am following this API documentation using Python to send a simple request for content from my locally hosted confluence server.

I am getting the following error:

[HTTP Status: 500 >> ERROR {'X-ASEN': 'SEN-L14880621', 'Content-Type': 'text/html;charset=utf-8', 'Content-Language': 'en', 'Transfer-Encoding': 'chunked', 'Date': 'Thu, 23 Jan 2020 13:49:57 GMT', 'Connection': 'close'}]

 

I have generated an API token from the id.atlassian.com site and have built a string as follows

ACCESS_HEADER = base64.b64encode('<username>@localhost:8090:<password>'.encode('utf-8'))

as described in the confluence API documentation.

 

I haven't been able to authenticate in any way so far. If anyone knows what I'm doing wrong, please help!

ALSO the following is my request: 

url = 'http://localhost:8090/rest/api/content'

response = requests.get(url,
headers={
'Authorization': 'Basic {}'.format(ACCESS_HEADER),
'Content-Type': 'application/json',
"Origin": "http://localhost:8090"
}
)

if response.status_code == 200:
respJSON = response.json()
else:
respJSON = '[{0} >> ERROR {1}]'.format(response.status_code, response.headers)

print(respJSON) 

 

Thanks in advance!! and please let me know if you require more details

1 answer

1 accepted

1 vote
Answer accepted
sykes_98 January 28, 2020

So after a lot more Googling and testing I FINALLY found a solution that seems to work as of right now.

 

The request (python):

## PAGE DATA FOR PAGE TO BE CREATED

page_data = {'type': 'page', 'space': {"key": space}, 'title': title,
"body": {"storage": {
"value": "<ENTER PAGE DATA HERE>",
"representation": "storage"}}}
## REQUEST

r = requests.post('http://localhost:8090/rest/api/content',
data=json.dumps(page_data),
auth=('username', 'password'), # note: this username and password do not need to be base64 encoded.
headers=({'Content-Type': 'application/json'}))

This example shows creating the page.

 

If anyone has any questions regarding this answer, please comment and I will try my best to help! 

Deleted user July 30, 2020

hi, im trying to connect to confluence too with python, also my second day with python coding , why is your confluence page localhost, 

I go to this url for my confluence documentation : 

 

https://devconfluence.cyberport.de/display/BI/Business+Intelligence

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events