From 454454f65fb10b47c753d62489fe857e52645829 Mon Sep 17 00:00:00 2001 From: Neo Date: Wed, 17 Jan 2018 13:36:06 +0200 Subject: [PATCH] Fix improper use of Requests for file upload The data structure prepared by `format_file_params` is supposed to be a list of tuples with a certain structure, not the dict one created currently. See https://github.com/HelloFax/hellosign-python-sdk/issues/34 for details of the issue being addressed here. --- hellosign_sdk/utils/hsformat.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hellosign_sdk/utils/hsformat.py b/hellosign_sdk/utils/hsformat.py index d110c1f..2508515 100644 --- a/hellosign_sdk/utils/hsformat.py +++ b/hellosign_sdk/utils/hsformat.py @@ -22,6 +22,7 @@ # SOFTWARE. # +import os class HSFormat(object): ''' Authentication object using HelloSign's access token ''' @@ -42,10 +43,13 @@ def format_file_params(files): ''' Utility method for formatting file parameters for transmission ''' - files_payload = {} + files_payload = [] if files: for idx, filename in enumerate(files): - files_payload["file[" + str(idx) + "]"] = open(filename, 'rb') + files_payload.append(( + 'file[%s]' % idx, + (os.path.basename(filename), open(filename, 'rb')) + )) return files_payload @staticmethod @@ -129,4 +133,4 @@ def format_custom_fields(list_of_custom_fields): @staticmethod def strip_none_values(dictionary): if dictionary: - return dict((key, value) for (key, value) in dictionary.items() if value) \ No newline at end of file + return dict((key, value) for (key, value) in dictionary.items() if value)