################################################################################
# Call a Web Service
################################################################################
import urllib.request, urllib.parse
import json

sql = "SELECT * from student"

sql = urllib.parse.quote(sql)                           #perform url encoding

url      = 'https://workshop.sps.nyu.edu/~sultans/util/rest/REST.py'
param    = 'user=demo&pswd=demo&db=demo&dbtype=sqlite&format=json'
sql      = 'sql=' + sql
full_url = url +'?'+ param +'&'+ sql

response = urllib.request.urlopen(full_url)             #call the web service 

status  = response.status                       #should be 200 
reason  = response.reason                       #should be OK
headers = response.info()                       #a dictionary of response headers                

content = response.read()                       #read the returned data
#content = content.decode("utf-8")              #convert bytes into string

list = json.loads(content)                      #convert JSON into a list of dictionaries

print(list)                                    #for debugging