BigW Consortium Gitlab

Commit 881ede0d by Forest Godfrey

Fix a few issues with encoding

parent d4a1f866
......@@ -302,10 +302,14 @@ class API(object):
fields.append((name, str(value)))
content_type, body = encode_multipart_formdata(fields, files)
if url.find("inventory") > 0:
self.log("Body = " + str(body))
else:
url = '%s%s' % (self.api_url, url)
body = urlencode(kwargs)
content_type = 'application/x-www-form-urlencoded'
if url.find("inventory") > 0:
self.log("Body = " + str(body))
self.last_url = url
data = self._get_url(url, http_method, content_type, body)
......
......@@ -31,7 +31,13 @@ def encode_multipart_formdata(fields, files):
"""
BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
CRLF = '\r\n'
L = byteEncoder(CRLF)
L = []
if files and (len(files) > 0):
print "encode_multipart_formdata Using byteEncoder"
L = byteEncoder(CRLF)
else:
print "encode_multipart_formdata: Using Normal API for request encoding"
for (key, value) in fields:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
......@@ -47,7 +53,10 @@ def encode_multipart_formdata(fields, files):
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = L.value()
if files and (len(files) > 0):
body = L.value()
else:
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment