I am trying to create a page in Confluence with the python API. I tried it like written here:
How can I create a new page to confluence with Python
This is my code:
from atlassian import Confluence
import requests
import json
from requests.auth import HTTPBasicAuth
confluence = Confluence(
url='..',
username='...`,
password='...')
page_title = 'My New Page'
page_html = '<p>This page was created with Python!</p>'
parent_page_id = ...
space_key = '...'
auth_token = ".."
basic_auth = HTTPBasicAuth('mail', auth_token)
url = 'https://.../rest/api/content/'
# Request Headers
headers = {
'Content-Type': 'application/json;charset=iso-8859-1',
}
# Request body
data = {
'type': 'page',
'title': page_title,
'ancestors': [{'id':parent_page_id}],
'space': {'key':space_key},
'body': {
'storage':{
'value': page_html,
'representation':'storage',
}
}
}
try:
r = requests.post(url=url, data=json.dumps(data), headers=headers, auth=basic_auth)
# Consider any status other than 2xx an error
if not r.status_code // 100 == 2:
print("Error: Unexpected response {}".format(r))
else:
print('Page Created!')
except requests.exceptions.RequestException as e:
# A serious problem happened, like an SSLError or InvalidURL
print("Error: {}".format(e))
my first question: where do I get the token? With this token https://id.atlassian.com/manage-profile/security/api-tokens it doesn't work.
second the output is:
Unexpected response <Response [401]> I think the authentication doesn't work. But i dont know how to authenticate....
If I try this:
oauth_dict = {
'access_token': 'access_token',
'access_token_secret': 'access_token_secret',
'consumer_key': 'consumer_key',
'key_cert': 'key_cert'}
https://atlassian-python-api.readthedocs.io/index.html
Where do i get the secret token, the consumer key and the key_cert??
pls help..