Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.
This repository was 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

Description

@jeteon

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.

Activity

  1. jeteon commented on Jan 17, 2018

    @jeteon
    Author

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

  2. alexmac05 commented on Jan 22, 2018

    @alexmac05
    Contributor

    Discussion of this issue is on the Pull Request #35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    legacyRelated to legacy, non-OpenAPI SDK

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions