I've tried various ways to get this working, but although I can view the confluence_url in a browser with no issue (so the URL is valid), I'm not able to return the contents of the page in Python v3. Where am I going wrong? any obvious issues? I'm guessing the issue is authentication.
note: I use the same authentication method for Jira and have no issue.
import base64
import requests
personal_access_token = "xxxxxxxx"
organizational_url = "https://confluence.global.xxx.com/"
authorization = str(base64.b64encode(bytes(':'+personal_access_token, 'ascii')),'ascii')
headers = { 'Accept': 'application/json', 'Authorization': 'Bearer '+authorization }
confluence_url = organizational_url+'rest/api/content/123456789?expand=body.storage'
response = requests.get(url=confluence_url, headers=headers, verify=False)
print(response.status_code)
print(response.text)
response.status_code is 404,
response.text is {"statusCode":404,"data":{"authorized":false,"valid":true,"allowedInReadOnlyMode":true,"errors":[],"successful":false},"message":"No content found with id: ContentId{id=123456789}","reason":"Not Found"}
Solved! The issue was that I didn't need to encode the personal_access_token. Solution is to remove the line "authorization = str(base64.b64encode(bytes(':'+personal_access_token, 'ascii')),'ascii')" and replace with simply "authorization = personal_access_token"
are u sure that user used for authentication is able to access that page?
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes, because I can copy and paste the confluence_url to a browser and it returns the data.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.