Skip to content

Instantly share code, notes, and snippets.

@marshyski
Created October 6, 2014 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshyski/7de895ee498776d1f713 to your computer and use it in GitHub Desktop.
Save marshyski/7de895ee498776d1f713 to your computer and use it in GitHub Desktop.
Create page and attach file under a confluence wiki site with Python Suds
#!/usr/bin/python
# yum install python-suds
import suds
import base64
# Uncomment the logging if you want to see the XML input and output for debugging
import logging
import logging.handlers
# Turn on logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('suds.client')
# Setup logging to file
logger.setLevel(logging.DEBUG)
url = 'http://wiki.finra.org/confluence/rpc/soap-axis/confluenceservice-v2?wsdl'
client = suds.client.Client(url)
# Get the session token
sessionId = client.service.login(in0 = 'john-username-goes-here', # USER
in1 = 'john-password-goes-here') # PW
# Load Confluence bean:RemoteAttachment namespace
attachns = '{http://beans.soap.rpc.confluence.atlassian.com}RemoteAttachment'
remoteAttachment = client.factory.create(attachns)
remoteAttachment.comment = ''
# Confluence will complain if content type is blank
remoteAttachment.contentType = 'text'
remoteAttachment.creator = 'john@email-account.com'
remoteAttachment.fileName = 'file-you-want-to-attach-here.txt'
remoteAttachment.title = ''
remoteAttachment.fileSize = 0
remoteAttachment.id = 0
remoteAttachment.pageId = 0
fileData = base64.b64encode("Some test data 1")
result = client.service.addAttachment(in0 = sessionId,
# Page ID for test page on Wiki site
in1 = 464388444,
in2 = remoteAttachment,
in3 = fileData
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment