JSON API » Sample clients » Python

#!/usr/bin/env python

# This is a sample client for the Enswitch JSON API.
# It is released into the public domain.
# It comes with absolutely no warranty, and is not supported.

import json, sys, urllib2

base = 'http://enswitch.example.com/api/json/'
function = 'access/list'
username = 'testuser'
password = 'testpass'

reply = urllib2.urlopen( base + function + '/?auth_username=' + username + ';auth_password=' + password )
output = json.load( reply )
fatal = 0
for r in output[ 'responses' ]:
    if int( r[ 'code' ] ) >= 400:
        print >>sys.stderr, r[ 'message' ]
        fatal = 1
if fatal:
    sys.exit( 1 )

for d in output[ 'data' ]:
    print 'Remote access account id=', d[ 'id' ], ', name=', d[ 'name' ]