Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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']
Comments
drupal_services.py updated
I wrote this page after I found out that the linked drupal_services.py project was outdated.
I found an updated project on github and I've updated the documentation in http://drupal.org/node/763066
https://github.com/dgtlmoon/python_drupal_services/blob/master/drupal_se...
Service 3
hello I launched the updated drupal_services.py (node creation test) with Service 3.1 and I get "Access denied for user anonymous" even though I'm using admin credentials, does it work for you ?
my quick fix for
my quick fix for drupal_services.py
line 57
- result = re.search('.+(SESS.*?;)', response.getheader("Set-Cookie", 0), re.IGNORECASE)
- if result is not None:
- self.cookie = result.group(1)
+ self.cookie = response.getheader("Set-Cookie", 0)
also line 97
- return getattr(self, method_name)(args[0])
+ return getattr(self, method_name)(*args)
example?
I am pretty new to python, do you mind giving some example code of how to use this class.
Thank you in advance.
Python code working with Services 3 and Drupal 7
With Services 3 and Drupal 7 I have to use a token to avoid an error: "401 CSRF Invalid". This is the code that worked for me:
Hope this helps!
Python code working with Services 3 and Drupal 7
With Services 3 and Drupal 7 I have to use a token to avoid an error: "401 CSRF Invalid". This is the code that worked for me:
Hope this helps!
example with python 3.x
I'm working with python 3.x and found out that things work somewhat differently. Eventually I figured it out. I'm posting the result here.
only thing i can't get to work is extra fields (custom fields).
But hopefully someone can use this.