Log in

No account? Create an account
Using Python and XMLRPC to post to LJ - LiveJournal Client Discussions — LiveJournal [entries|archive|friends|userinfo]
LiveJournal Client Discussions

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Using Python and XMLRPC to post to LJ [May. 1st, 2006|04:05 am]
LiveJournal Client Discussions


[mood |curiouscurious]

I'm VERY new at this. (Both to using XMLRPC and Python, infact I wouldn't say I really know what I'm doing, merely coding from imitation and some basic knowledge of the general syntax of most programming languages.) Basically I started doing this when it seemed like the Blogger API had been removed from Livejournal. I couldn't make a post using it. So, I set about altering my application to use the LiveJournal XMLRPC. It's a very quick and dirty hack, I'm passing passwords in the clear essentially. I'm VERY close, it works for LJ.XMLRPC.login, but when I try LJ.XMLRPC.postevent I get the following error message:

XML-RPC Fault: ServerCan't use string ("1") as a HASH ref while "strict refs" in use at /home/lj/cgi-bin/ljprotocol.pl line 2527, [anglebracket]GEN2[anglebracket] line 41.

I added the [anglebracket] thing there. The line number following Gen2 changes with each try, so I'm not sure if it really matters. Here's the Code for the function responsible for creating the post:

def newPostLiveJournal(logger, audioFilePath, cgiAudioFilePath, AuthMethod, LineEndings,
xmlrpcServer, blogID, userName, password, publish, useNewMediaObject, nmoDestPath):
"""Adds a new post to a LiveJournal"""

logger.write('In newPostLiveJournal\n')
postID = {}
postID['itemid'] = -1
LJEvent = {}
LJEvent['username'] = userName
LJEvent['auth_method'] = AuthMethod
LJEvent['password'] = password
LJEvent['event'] = '

This post was created with PhoneBlogger. ' \
+ 'Click to listen to the ' \
+ 'recorded message.

LJEvent['lineendings'] = LineEndings
LJEvent['subject'] = 'Post from PhoneBlogger'
LJEvent['year'] = time.localtime()[0]
LJEvent['mon'] = time.localtime()[1]
LJEvent['day'] = time.localtime()[2]
LJEvent['hour'] = time.localtime()[3]
LJEvent['min'] = time.localtime()[4]
logger.write('Set LJEvent\n')
postID = xmlrpcServer.LJ.XMLRPC.postevent(LJEvent and xmlrpclib.True or xmlrpclib.False)
except xmlrpclib.Fault, fault:
logger.write('XML-RPC Fault: ' + fault.faultCode + fault.faultString + '\n')
return postID['itemid']

Does anyone have any ideas as to what could be wrong, or how I can go about debugging this?

[User Picture]From: evilhat
2006-05-03 10:19 pm (UTC)
Just for reference, my own open source, Python-based client, Charm, successfully implements a range of protocols -- LiveJournal's traditional and XML-RPC interfaces, the Atom API (Blogger, Movable Type, etc.), and the Metaweb API.

You may want to look at that for code examples.

(Reply) (Thread)