from urllib import urlencode
from urllib2 import Request, urlopen

def postit(url,fields):

    postdata = urlencode(fields)
    headers = {'Content-Type': 'application/x-www-form-urlencoded',
               'Content-Length': str(len(postdata))}
    r = Request(url, postdata, headers)

    pg = urlopen(r)
    text = pg.read()
    return text


if __name__ == '__main__':
    role = 's000004'
    passw = 'abcABCdefDEF'
    flds = [ ('q', 'SELECT 1+1 as sum'),
             ('format', 'json'),
             ('authcode', passw) ]
    url = 'http://www.rdbhost.com/db/'+role
    val = postit(url,flds)
    print val

