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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

1,720 views 25 10
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