Example: Authenticate user and create node using Services 3.0 XML-RPC and Python

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

After you have exposed the node and user resources you can first log in a user and perform an action with the session cookie returned. To keep the session cookie I am using some code from Roberto Rocco Angeloni:
http://www.roccoangeloni.it/wp/2008/06/13/xmlrpclib-with-cookie-aware-tr...

Then:

tr = CookieTransport()
server = xmlrpclib.Server(url, transport=tr)
server.system.connect()
user = server.user.login('user','password')
tr.SESSION_ID_STRING = user['session_name']
tr.mysessid = user['sessid']
new_node = {'body': 'Ordenar bibliotecas es ejercer de un modo silencioso el arte de la critica.\n-- Jorge Luis Borges. (1899-1986) Escritor argentino.', 'type': 'page', 'title': 'Just a little test'}
server.node.create(new_node)
server.node.retrieve(10)['uid']

Help improve this page

Page status: Not set

You can: