Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

SOLVED: How do I authenticate for Confluence in the Atlassian Python API?

Daniel September 29, 2020

SOLVED: Found out that I needed to use the space code instead of its actual name when creating the confluence page.

I have been trying to figure out for hours how to use the Atlassian Python API to do anything in Confluence, and I just can't for the life of me figure out how to authenticate. According to this documentation of the API, I should be able to do this

confluence = Confluence(
    url='http://localhost:8090',
    username='admin',
    password='admin')

 But it just doesn't work. Another option it gives is a key/cert authentication and I can't figure out how to set that up, and another option is Oauth, and I've looked at probably 5 different pages trying to figure out how to enable that somehow but nothing tells me where the setting is.

I'm just so lost. Any help would be greatly appreciated. Thank you.

2 answers

1 accepted

0 votes
Answer accepted
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 1, 2020

Hello Daniel, welcome to the Community!

I'm glad you were able to sort this question out and get the python library working with your local Confluence Server instance. We're here to answer any additional questions if they come up!

Cheers,
Daniel | Atlassian Team

1 vote
Nikhilesh Saggere November 20, 2020

Hi,

Can you please provide the example/answer. I am not able to figure out how to authenticate using the api?

Daniel November 20, 2020

It turned out that the confluence function I used in my original question wasn't the actual problem for me. What it turned out was that in the create function, I was using the actual name of the space for the space name argument, when it actually needed the three-digit code for the space. So for example my space name was "Test", but its code was "TES". I had been using "Test" for the space name but I needed to use "TES".

If this isn't your problem, then I can tell you that another problem I had, which was figuring out what to use for the confluence function that is shown in the original question. For username, use your email. For password, use an API token.

Like Nikhilesh Saggere likes this
Nikhilesh Saggere November 20, 2020

Thank you Daniel for your response!

I tried using the below mentioned to get authenticated to the confluence page and extract the information. 

# coding=utf-8
from atlassian import Confluence

confluence = Confluence(url="http://confluence.companyname.com", username="user1", password="passkey")

# If you know Space and Title
content1 = confluence.get_page_by_title(space="SPACE", title="page title")

print(content1)

# If you know page_id of the page
content2 = confluence.get_page_by_id(page_id=1123123123)

print(content2) 

 However, i get the following error, when the above snippet is executed

raise HTTPError(http_error_msg, response=self)

requests.exceptions.HTTPError: 401 Client Error:  for url: https://confluence.sw.companyname.com/rest/api/content?start=0&limit=1&spaceKey=SPACE&title=title

Going by the error code 401; it is still an authentication failure. 

From https://community.atlassian.com/t5/Confluence-questions/No-more-Python-API-working-for-Confluence/qaq-p/1075027 the API token method is the only way forward.

 

Could you please provide me an example or point me to the code snippet where the API method is used to get the authentication step passed and able to extract the info.

I have generated the API key, but not sure how to use it the atlssaina-python API methods.

Please help.

Many Thanks!!

Sarah Mac Crossan August 31, 2021

Hi Nikhilesh, did you have any luck resolving this?

Nikhilesh Saggere August 31, 2021

yes please use curl utility in linux or requests module in python

Like Werner Oswald likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events