How do I use addProfilePicture() in python?

I'm looking at the docs: http://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/rpc/soap/XhtmlSoapService.html#addProfilePicture(java.lang.String, java.lang.String, java.lang.String, java.lang.String, byte[])

and I am able to login. Now I am trying to add a profile picture (I do have permissions) and the code looks like this:

with open('C:/roster/face.png', 'rb') as p:

pic = p.read()

server.confluence1.addProfilePicture( token, userName, 'face.png', 'image/png', pic )

And the (truncated for brevity) error I get is:

File "R:\Tools\Python\2.6\lib\xmlrpclib.py", line 604, in close

self._parser.Parse("", 1) # end of data

ExpatError: no element found: line 1, column 0

What am I doing wrong? I know my token and userName are correct. There isn't much direction for the mime type but it looks like that's all it expects. I hope the docs get more examples.

1 answer

1 accepted

This widget could not be displayed.

The following script works for me:

#!/usr/bin/python

import xmlrpclib

"""
create a proxy object with methods that can be used
to invoke corresponding RPC calls on the remote server
"""
server = xmlrpclib.ServerProxy('http://path.to.your.confluence/rpc/xmlrpc')

try:
    """ log in a user
    Returns a String authentication token to be passed as authentication to
    all other remote calls. It's not bulletproof auth, but it will do for now.
    Must be called before any other method in a 'remote conversation'.
    From 1.3 onwards, you can supply an empty string as the token to be treated
    as being the anonymous user.
    """
    token = server.confluence1.login('username', 'password');

    """ add profile picture
    Read a file and add it as new profile picture to specified user
    """
    pictureData = xmlrpclib.Binary(open('/path/to/avatar.png').read())
    profilePictureAdded = server.confluence1.addProfilePicture(token, 'username', 'avatar.png', 'image/png', pictureData)
    if profilePictureAdded:
        print "Successfully added new profile picture..."
    else:
        print "Failed to add new profile picture..."

except xmlrpclib.Fault, err:
    print "Fault code: %d" % err.faultCode
    print "Fault string: %s" % err.faultString

Hope this helps

I had to open() with 'rb', but that is exactly what I was looking for. Thanks!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

411 views 4 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you