[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
myrpcservice.setServiceParent(multiService)
#Set created application to be serviceparent of multiservice
multiService.setServiceParent(application)
---------------

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>
<html>
<head>
	<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">
		$(document).ready(function(){
				 $('#getData').live('click', function(){
						$jsonArray ='{"action" : "aksi","myval1" : "val1", "myval2" :{"myval2a":"val2a","myval2b":"val2b"}}';
						$arr = JSON.stringify($jsonArray);
						$.get("http://127.0.0.1:50008/JSONRPC",{data:$arr},function(response){
							$("#showdata").html(response);
						});						
				 });
		 });
	</script>
</head>
<body>
<button  id="getData">Get JSON Data</button>
<div  id="showdata"></div>
</body>
</html>

---------------
My log file say :
File "/usr/lib/pymodules/python2.6/simplejson/decoder.py", line 420, in 
raw_decode
         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,127.0.0.1] 127.0.0.1 - - 
[13/Jan/2012:03:56:29 +0000] "GET 
/JSONRPC?data=%22%7B%5C%22action%5C%22+%3A+%5C%22aksi%5C%22%2C%5C%22myval1%5C%22+%3A+%5C%22val1%5C%22%2C+%5C%22myval2%5C%22+%3A%7B%5C%22myval2a%5C%22%3A%5C%22val2a%5C%22%2C%5C%22myval2b%5C%22%3A%5C%22val2b%5C%22%7D%7D%22 
HTTP/1.1" 500 14369 "http://127.0.0.1/taxi-get.html" "Mozilla/5.0 (X11; 
U; Linux i686; en-US; rv:1.9.2.18) 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 ?

Sincerely
-bino-
-------------- 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