Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Incorrect use of requests leads to random order for multiple files #34

Open
jeteon opened this issue Jan 17, 2018 · 2 comments
Open

Incorrect use of requests leads to random order for multiple files #34

jeteon opened this issue Jan 17, 2018 · 2 comments
Labels
legacy Related to legacy, non-OpenAPI SDK

Comments

@jeteon
Copy link

jeteon commented Jan 17, 2018

When a signature request is created with multiple files, the SDK sends them in a manner that results in them appearing in random order when they have to be signed. I've been digging into this and have found the cause which I'll explain below.

When a signature request is created that includes files, the HSClient class uses the HSFormat class to convert them into a data structure used in the request: https://github.com/HelloFax/hellosign-python-sdk/blob/ac8a1fcea8f4c2fdc56a408bc4d50efa7c6bfd91/hellosign_sdk/hsclient.py#L1383 like so: https://github.com/HelloFax/hellosign-python-sdk/blob/ac8a1fcea8f4c2fdc56a408bc4d50efa7c6bfd91/hellosign_sdk/hsclient.py#L1427

However the HSFormat creates an inappropriate data structure for this:https://github.com/HelloFax/hellosign-python-sdk/blob/ac8a1fcea8f4c2fdc56a408bc4d50efa7c6bfd91/hellosign_sdk/utils/hsformat.py#L40-L49

Basically, it creates a dictionary with a "file[j]" key for each file. This dictionary is eventually fed into a call to the post method of the Requests library as the files argument: https://github.com/HelloFax/hellosign-python-sdk/blob/ac8a1fcea8f4c2fdc56a408bc4d50efa7c6bfd91/hellosign_sdk/utils/request.py#L167

However, the documentation for the Requests library states that a list (which is an ordered iterable) be used for this argument here and the example clearly is of a list of tuples:

>>> url = 'http://httpbin.org/post'
>>> multiple_files = [
        ('images', ('foo.png', open('foo.png', 'rb'), 'image/png')),
        ('images', ('bar.png', open('bar.png', 'rb'), 'image/png'))]
>>> r = requests.post(url, files=multiple_files)
>>> r.text

What I'm guessing happens is that the Requests library converts the dictionary into a list, ignoring the keys and appending only the values in a random order because dict is an unordered data structure.

jeteon added a commit to jeteon/hellosign-python-sdk that referenced this issue Jan 17, 2018
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 hellosign#34 for details of the issue being addressed here.
@jeteon
Copy link
Author

jeteon commented Jan 17, 2018

I've submitted #35 with the fix for this.

@alexmac05
Copy link
Contributor

Discussion of this issue is on the Pull Request #35

@jtreminio-dropbox jtreminio-dropbox added the legacy Related to legacy, non-OpenAPI SDK label Apr 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
legacy Related to legacy, non-OpenAPI SDK
Projects
None yet
Development

No branches or pull requests

3 participants