conflunce & curl

import requests
import json
import base64# Set the confluence User and Password for authentication
user = ‘xxxxx’
password = ‘xxxxx’# Set the title and content of the page to create
page_title = ‘My New Page’
page_html = ‘<p>This page was created!</p>’# You need to know the parent page id and space key.
# You can use the /content API to search for these values.
# Parent Page example http://example.com/display/ABC/Cheese
# Search example: http://example.com/rest/api/content?title=Cheese
parent_page_id = xxxxx
space_key = ‘xxxxx’# Request URL – API for creating a new page as a child of another page
url = ‘http://xx.xx.x.xx:xxxx/rest/api/content/‘# Create the basic auth for use in the authentication header
#auth = base64.b64encode(b'{}:{}’.format(user, password))
#auth = base64.b64encode(b'{%s}:{%s}’ % (user, password))
auth_str = ‘%s:%s’ % (user, password)
#b64_auth_str = base64.b64encode(auth_str.encode(‘utf-8′))
#print(b64_auth_str)#’Authorization’: ‘Basic {}’.format(b64_auth_str),
# Request Headers
headers = {
  ‘Authorization’: ‘%s’ % auth_str,
  ‘Content-Type’: ‘application/json’,
}# Request body
data = {
  ‘type’: ‘page’,
  ‘title’: page_title,
  ‘ancestors’: [{‘id’:parent_page_id}],
  ‘space’: {‘key’:space_key},
  ‘body’: {
      ‘storage’:{
          ‘value’: page_html,
          ‘representation’:’storage’,
      }
  }
}# We’re ready to call the api
try:   r = requests.post(url=url, data=json.dumps(data), headers=headers)   # 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))

댓글 남기기