How to access Confluence using personal access token for organization that requires 2FA

Matthew Kennedy July 27, 2022

Hello,

I am trying to access pages via the `atlassian-python-api` library in Python. I have read through this page on authentication and tried every method, but none of them have worked for me. Each attempt, I get a 401. I have created a personal access token both through my Atlassian account, as well as directly on Confluence. Below is a code snippet - my assumption is that I am getting 401 every time due to the 2FA requirement. What is the right way to fix this so I can get access to my organization's Confluence pages via python?

 

Additionally, is there a login method that is something similar to opening a browser and having the user login to their Confluence account there, instead of using an API token?

 

from atlassian import Confluence

email = 'me@org.com'
confluence_api_token = 'confluenceApiToken'
atlassian_api_token = 'atlassianApiToken'

confluence = Confluence(
url=domain,
username=email,
password=confluence_api_token,
cloud=True)


confluence.get_all_spaces(start=0, limit=5, expand=None)

 

 

2 answers

0 votes
amaan khan July 28, 2022

Hey, Matthew. I am facing a similar problem. Were you able to come up with a solution for it yet?

Matthew Kennedy July 28, 2022

Hi Amaan, I was able to make my own solution, which unfortunately didn't use a placeholder, but is ultimately a better option. I ended up using selenium to create a web browser, then have the user log in, and once the user was logged in, I saved the cookies to a Netscape HTTP Cookies File format, and using those cookies to authenticate has worked fine.

0 votes
Andy Gladstone
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 27, 2022

@Matthew Kennedy welcome to the Atlassian Community.

This seems to be a question about Confluence rather than a question related to the add-on Questions for Confluence. I am moving this to the Confluence collection to get more eyes on this and hopefully an answer for you.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events