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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :
have you tried creating nodes that has term reference fields ?
Thanks