How do I use addProfilePicture() in python?

I'm looking at the docs:, 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 =

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\", 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

4 votes
Accepted answer

The following script works for me:


import xmlrpclib

create a proxy object with methods that can be used
to invoke corresponding RPC calls on the remote server
server = xmlrpclib.ServerProxy('')

    """ 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..."
        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 Feb 06, 2019 in Confluence

Try out the new editing experience

Hi team, I’m Avinoam, a product manager on Confluence Cloud, and today I’m really excited to let the Community know that all customers can now try out the new editing experience and see some of the ...

783 views 33 5
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