[Twisted-Python] Question : How to web test txjsonrpc ?

bino oetomo bino at indoakses-online.com
Thu Jan 12 23:13:45 EST 2012

Dear All ...

I have a basic txjsonrpc script, like :
from twisted.application import internet, service
from txjsonrpc.web import jsonrpc
from twisted.web import server

from twisted.internet import reactor

import traceback

class MyRPC(jsonrpc.JSONRPC):
     def __init__(self):
         self.allowNone = True
         self.useDateTime = False

         #variabel untuk menampung koneksi xmppclient
         #perlu disiapkan terlebih dahulu
     def jsonrpc_aksi(self, msg):
         print 'JSON MSG',
         print msg
         print '------'
         print msg['myvar']
         print '\n'
         return 'OK'

#Create Application
application = service.Application("Serial MultiService Example")

#build jsonrpc site
myrpc = MyRPC()
site = server.Site(myrpc)
myrpcservice = internet.TCPServer(50008, site, interface='localhost')

#Creating Multi Service
multiService = service.MultiService()
#Add our Services to multiservice
#Set created application to be serviceparent of multiservice

Those script is work fine ...I mean can be accessed via python based 
jsonrpc client.

But now i need to call this rpc server via web interface.
Since I don't have enough knowledge on web-based JSONRPC client , i do 
search google for it ... but I can't understand.
So I ask my friend to write some simple JSONRPC client , and he send me 
this litle html

<!DOCTYPE html>
	<script  type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js  <view-source:http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js>"></script>
	<script  type="text/javascript">
				 $('#getData').live('click', function(){
						$jsonArray ='{"action" : "aksi","myval1" : "val1", "myval2" :{"myval2a":"val2a","myval2b":"val2b"}}';
						$arr = JSON.stringify($jsonArray);
<button  id="getData">Get JSON Data</button>
<div  id="showdata"></div>

My log file say :
File "/usr/lib/pymodules/python2.6/simplejson/decoder.py", line 420, in 
         raise JSONDecodeError("No JSON object could be decoded", s, idx)
     simplejson.decoder.JSONDecodeError: No JSON object could be 
decoded: line 1 column 0 (char 0)

And I think the received web request is reported as :
2012-01-13 10:56:29+0700 [HTTPChannel,3,] - - 
[13/Jan/2012:03:56:29 +0000] "GET 
HTTP/1.1" 500 14369 "" "Mozilla/5.0 (X11; 
U; Linux i686; en-US; rv: Gecko/20110628 Ubuntu/10.10 
(maverick) Firefox/3.6.18"

So , kindly please give me (or refer me to)  any simple sample of 
web-based JSONRPC client .. using GET and/or POS methode ?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120113/17616fe6/attachment-0001.htm 

More information about the Twisted-Python mailing list