Skip to content
Snippets Groups Projects
Commit f7a78116 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Drop none-valued query parameters by default

parent 83772a26
No related branches found
No related tags found
2 merge requests!50Release 2024.06.03,!46Issue0038
......@@ -13,18 +13,27 @@ HOST = '127.0.0.1'
PORT = 6221
uri = 'http://{}:{}/'.format(HOST, PORT)
def hit_endpoint(method, endpoint, params=None, body=None):
def hit_endpoint(method, endpoint, params=None, body=None, drop_none=True):
"""
Python 2.7 implementation of HTTP client
:param method: (str) either 'GET' or 'PUT'
:param endpoint: (str) endpoint of HTTP request
:param params: (dict) of parameters that are embedded in client request URL
:param body: (dict) of parameters that JSON-encoded and attached as payload in request
:param drop_none: (bool) remove (presumably optional) parameters with value equal to None
:return: (dict) of response status and content, formatted as dict if request is successful
"""
connection = httplib.HTTPConnection(HOST, PORT)
if not method in ['GET', 'PUT']:
raise Exception('Can only handle GET and PUT requests')
k_pop = []
if drop_none:
for k, v in params.items():
if v is None:
k_pop.append(k)
for ki in k_pop:
params.pop(ki)
if params:
url = endpoint + '?' + urllib.urlencode(params)
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment