Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I use addProfilePicture() in python?

Pat Corwin July 26, 2012

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

4 votes
Answer accepted
Remo Siegwart
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 26, 2012

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

Pat Corwin July 27, 2012

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
TAGS
AUG Leaders

Atlassian Community Events