2

I need to access a Confluence page via python script, but although I found some examples online, I wasn't able to do it.

Here are a few attempts:

import requests

urllogin = 'https://myorg/confluence/display/path/to/page'
login = requests.get(urllogin, auth=('myusername', 'mytoken'))
print(login.status_code)
from atlassian import Confluence

confluence = Confluence(
    url='https://myorg/confluence/display/path/to/page',
    username='myusername',
    password='mytoken')

It doesn't seem to be a token issue: I tried using an Atlassian API token https://id.atlassian.com/manage-profile/security/api-tokens or Google API token (my org uses Google credentials to access Confluence as well). Using login credentials didn't work either.

buddemat
  • 4,552
  • 14
  • 29
  • 49
slick2019
  • 51
  • 2
  • 7

1 Answers1

2

You have two issues in your attempt.

First, the url needs to be the base url of your confluence site, so in your case something along the lines of url='https://conf.myorg.com'.

Second, using the parameters username= and password= is for basic auth. But I guess you want OAuth? Or is the token you are referring to an Atlassian API token? Either way, an overview of all different authentication modes can be found in the documentation. The following examples are taken from there.

OAuth:

from atlassian import Confluence

oauth_dict = {
    'access_token': 'access_token',
    'access_token_secret': 'access_token_secret',
    'consumer_key': 'consumer_key',
    'key_cert': 'key_cert'}

confluence = Confluence(
    url='http://localhost:8090',
    oauth=oauth_dict)

API token:

from atlassian import Confluence

# Obtain an API token from: https://id.atlassian.com/manage-profile/security/api-tokens
# You cannot log-in with your regular password to these services.

confluence = Confluence(
    url='https://your-domain.atlassian.net',
    username=jira_username,
    password=jira_api_token,
    cloud=True)
buddemat
  • 4,552
  • 14
  • 29
  • 49