Skip to content

Instantly share code, notes, and snippets.

@Palleas
Created March 18, 2013 13:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Palleas/5187018 to your computer and use it in GitHub Desktop.
Save Palleas/5187018 to your computer and use it in GitHub Desktop.
Upload a file to confluence using python
#!/usr/bin/python
from __future__ import with_statement
import sys, string, xmlrpclib, re, os
if len(sys.argv) < 5:
exit("Usage: " + sys.argv[0] + " spacekey pagetitle contentType filename");
spacekey = sys.argv[1];
pagetitle = sys.argv[2];
contentType = sys.argv[3];
filename = sys.argv[4];
with open(filename, 'rb') as f:
data = f.read(); # slurp all the data
server = xmlrpclib.ServerProxy('https://your-url/confluence/rpc/xmlrpc');
token = server.confluence2.login('your-login', 'your-password');
page = server.confluence2.getPage(token, spacekey, pagetitle);
if page is None:
exit("Could not find page " + spacekey + ":" + pagetitle);
attachment = {};
attachment['fileName'] = os.path.basename(filename);
attachment['contentType'] = contentType;
server.confluence2.addAttachment(token, page['id'], attachment, xmlrpclib.Binary(data));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment