It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

[Confluence Server] Cannot authenticate with REST APIs

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

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! 

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
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

4,120 views 4 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you