Skip to content
Snippets Groups Projects
client.py 698 B
Newer Older
import httplib
import json
import urllib

import sys
print(sys.version)

HOST = '127.0.0.1'
uri = 'http://{}:{}/'.format(HOST, PORT)

def hit_endpoint(method, endpoint, params=None, verbose=False):
    connection = httplib.HTTPConnection(HOST, PORT)
    if not method in ['GET', 'PUT']:
        raise Exception('Can only handle GET and PUT requests')
    if params:
        url = endpoint + '?' + urllib.urlencode(params)
    else:
        url = endpoint
    connection.request(method, url)
    resp = connection.getresponse()
    resp_str = resp.read()
    if verbose:
    	print(method + ' ' + url + ', status ' + str(resp.status) + ':\n' + resp_str)
    return json.loads(resp_str)