I'm trying to get the session key from the Limesurvey API using Python 2.7 and I'm not getting any results after running my code. I've followed the example in the documentation but still get an error
<p>Error: <type 'exceptions.ValueError'></p>
. My code is as follows:
import urllib
import urllib2
import json
import sys
req = urllib2.Request(url='https://testone.limequery.com/index.php/admin/remotecontro,\
data='{\"method\":\"get_session_key\",\"params\":[\"admin\",\"Password\"],\"id\":1}')
req.add_header('content-type', 'application/json')
req.add_header('connection', 'Keep-Alive')
try:
f = urllib2.urlopen(req)
myretun = f.read()
j=json.loads(myretun)
print (j['result'])
except :
e = sys.exc_info()[0]
print ( "<p>Error: %s</p>" % e )
Removing the try catch gives me the error ValueError: No JSON object could be decoded
There's the
citric
Python library. It abstracts the JSON RPC interface and exposes the RPC methods as methods of theClient
class.Disclaimer: I'm the author.