Created
December 23, 2011 16:01
-
-
Save level09/1514559 to your computer and use it in GitHub Desktop.
Create Drupal Node with python thorough XMLRPC Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
import xmlrpclib, pprint | |
class DrupalNode: | |
def __init__(self, title, body, ntype='article', uid=1, username ='admin'): | |
self.title = title | |
self.body = body | |
self.type = ntype | |
self.uid = uid | |
self.status = 1 | |
self.name = username | |
config = { | |
'url': 'http://example.com/services/xmlrpc', | |
'username': 'admin', | |
'password': 'nidal', | |
} | |
s = xmlrpclib.ServerProxy(config['url']) | |
#print s.system.listMethods() | |
res = s.system.connect() | |
session = s.user.login(config['username'], config['password']); | |
#print session | |
sessname = session['session_name'] | |
sessid = session['sessid'] | |
user = session['user'] | |
n = DrupalNode('test node','node body ...') | |
try: | |
s.node.create(sessid, n) | |
except xmlrpclib.Fault, err: | |
print "A fault occurred" | |
print "Fault code: %d" % err.faultCode | |
print "Fault string: %s" % err.faultString | |
since protocol inspection is totally broken, I'm not really sure how to get this to work.
yes, but check out my fork, i got it work by using Cookie/header handling for the session
Cool, could you share a link please ?
Thanks, much appreciated
I got your code working fine ( I had to give anonymous permissions to create nodes) .
but for some reason I'm unable to create taxonomy terms (D7) , this code fails :
new_node = { 'type': 'page',
'uid' : '1',
'name': 'admin',
'title': 'Just a little test',
'language' : 'und',
'body': { 'und' : { '0' : {'value' : 'Ordenar bibliotecas es ejercer de un modo silencioso el arte de la critica. --- Jorge Luis Borges. (1899-1986) Escritor argentino.' } }} ,
'field_price': { 'und' : { '0' : {'value' : 'this is the price ... ' } }} ,
'field_color': { 'und' : { '0' : {'tid': '1'} }} ,
}
have you tried creating nodes that has term reference fields ?
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try:
s.node.create(sessid, n)
I dont think it supports 'sessid' being sent here anymore