My company stopped using passwords for authenticating to atlassian apps internally. They also moved authentication from ADFS to AAD.
This meant that my python script used to pull a table from a database and attach it to a confluence space broke and I now find myself in the position where I have to rewrite the authentication section to use a generated PAT.
I have tried to authenticate to the api using the following code but keep getting error 401 returned.
import request
import base64
auth_key = base64.b64encode(b'MY_ID:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').decode("ascii")
headers = { "Authorization": "Basic " + auth_key,
"Content-Type":"application/json"
}
response = requests.get("https://confluence.XXXXXXXX.XXXXXXXXXXX.com/rest/api/content?spaceKey=XXXXXXXXX&title=XXXXXXXXXXXXXXXXXXXX", headers=headers)
print(response.status_code)
I also tried to authenticate by swapping MY_ID (which worked with my password) with my email domain to no avail.
The next thing I tried was to supply the creds without encoding them using the base64 algorithm to no avail.
import requests
import base64
url = "https://confluence.xxxxxxxxx.xxxxxxxxxxxxxxx.com/rest/api/space/xxxxxxxxx"
auth = HTTPBasicAuth("MY_ID", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
headers = {
"Accept": "application/json"
"Content-Type":"application/json"
}
response = requests.request(
"GET",
url,
headers=headers,
auth=auth
)
print(response.status_code)
To compound to the misery, running the below curl command returns results on the command line:
curl -H "Authorization: Bearer xxxxxxxxxxxxxxxxxx" https://confluence.xxxxxxxxxx.xxxxxxxxxxxxxxxxxx.com/rest/api/content/xxxxxxxxxxxx?expand=body.storage,version
Additionally, I can successfully call the end point on postman using the pat that I generated.
What am I missing from my python code in order to get it to successfully authenticate?
Thanks for your help.