Build a form like curl -F

I wonder if it's possible to build a form within the requests library.
I want to do that to implement the download in github api (python-github3).

Here is the doc for the api v3 download :
curl \
-F "key=downloads/octocat/Hello-World/new_file.jpg" \
-F "acl=public-read" \
...
-F "file=@new_file.jpg" \
https://github.s3.amazonaws.com/

Any advice on how to do that with the requests library ?

Bye


Attaching form data is quite easy with requests:

``` python

import requests

url = 'https://github.s3.amazonaws.com/'
form = {
    'key': 'downloads/octocat/Hello-World/new_file.jpg',
    'acl': 'public-read',
    'file': '@new_file.jpg'
}

r = requests.post(url, data=form)

```


Hi, is there a way to order the form attributes : in the github v3 api, it is stated that when posting a download, the order of the form attribute is mandatory to be the same as the doc exemple.

Any advice on this ?

Here is a working curl post, followed by a non working requests post :

POST / HTTP/1.1
User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6
Host: github.s3.amazonaws.com
Accept: _/_
Content-Length: 2299
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------b7a77fa8ccb4

------------------------------b7a77fa8ccb4
Content-Disposition: form-data; name=" key"

downloads/kigeia/gepi/LICENSE-1-245
------------------------------b7a77fa8ccb4
Content-Disposition: form-data; name=" acl"

public-read
------------------------------b7a77fa8ccb4
Content-Disposition: form-data; name=" success_action_status"

201
------------------------------b7a77fa8ccb4
Content-Disposition: form-data; name=" Filename"

LICENSE-1-245
------------------------------b7a77fa8ccb4
Content-Disposition: form-data; name=" AWSAccessKeyId"

1DWESVTPGHQVTX38V182
------------------------------b7a77fa8ccb4
Content-Disposition: form-data; name=" Policy"

ewogICAgJ2V4cGlyYXRpb24nOiAnMjExMS0wOC0zMVQxMjoyMjozNS4wMDBaJywKICAgICdjb25kaXRpb25zJzogWwogICAgICAgIHsnYnVja2V0JzogJ2dpdGh1Yid9LAogICAgICAgIHsna2V5JzogJ2Rvd25sb2Fkcy9raWdlaWEvZ2VwaS9MSUNFTlNFLTEtMjQ1J30sCiAgICAgICAgeydhY2wnOiAncHVibGljLXJlYWQnfSwKICAgICAgICB7J3N1Y2Nlc3NfYWN0aW9uX3N0YXR1cyc6ICcyMDEnfSwKICAgICAgICBbJ3N0YXJ0cy13aXRoJywgJyRGaWxlbmFtZScsICcnXSwKICAgICAgICBbJ3N0YXJ0cy13aXRoJywgJyRDb250ZW50LVR5cGUnLCAnJ10KICAgIF0KfQ==
------------------------------b7a77fa8ccb4
Content-Disposition: form-data; name=" Signature"

Cdiawuw8CDChzxqE7lOdaaClo08=
------------------------------b7a77fa8ccb4
Content-Disposition: form-data; name=" Content-Type"

application/octet-stream
------------------------------b7a77fa8ccb4
Content-Disposition: form-data; name=" file"; filename="LICENSE-1-245"
Content-Type: application/octet-stream

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
------------------------------b7a77fa8ccb4--

# 

# 

POST / HTTP/1.1
Accept-Encoding: identity
Content-Length: 2522
Host: github.s3.amazonaws.com
Content-Type: multipart/form-data; boundary=7005673b2b0941909024b72cb0adf66c
Connection: close
User-Agent: python-requests.org

--7005673b2b0941909024b72cb0adf66c
Content-Disposition: form-data; name="AWSAccessKeyId"
Content-Type: text/plain; charset=utf-8

1DWESVTPGHQVTX38V182
--7005673b2b0941909024b72cb0adf66c
Content-Disposition: form-data; name="LICENSE-1-245"
Content-Type: text/plain; charset=utf-8

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--7005673b2b0941909024b72cb0adf66c
Content-Disposition: form-data; name="Filename"
Content-Type: text/plain; charset=utf-8

LICENSE-1-245
--7005673b2b0941909024b72cb0adf66c
Content-Disposition: form-data; name="key"
Content-Type: text/plain; charset=utf-8

downloads/kigeia/gepi/LICENSE-1-245
--7005673b2b0941909024b72cb0adf66c
Content-Disposition: form-data; name="Signature"
Content-Type: text/plain; charset=utf-8

z8EEaQtwIrVVCwjZqadKzE2b918=
--7005673b2b0941909024b72cb0adf66c
Content-Disposition: form-data; name="Policy"
Content-Type: text/plain; charset=utf-8

ewogICAgJ2V4cGlyYXRpb24nOiAnMjExMS0wOC0zMVQxMjo1MDoxMS4wMDBaJywKICAgICdjb25kaXRpb25zJzogWwogICAgICAgIHsnYnVja2V0JzogJ2dpdGh1Yid9LAogICAgICAgIHsna2V5JzogJ2Rvd25sb2Fkcy9raWdlaWEvZ2VwaS9MSUNFTlNFLTEtMjQ1J30sCiAgICAgICAgeydhY2wnOiAncHVibGljLXJlYWQnfSwKICAgICAgICB7J3N1Y2Nlc3NfYWN0aW9uX3N0YXR1cyc6ICcyMDEnfSwKICAgICAgICBbJ3N0YXJ0cy13aXRoJywgJyRGaWxlbmFtZScsICcnXSwKICAgICAgICBbJ3N0YXJ0cy13aXRoJywgJyRDb250ZW50LVR5cGUnLCAnJ10KICAgIF0KfQ==
--7005673b2b0941909024b72cb0adf66c
Content-Disposition: form-data; name="acl"
Content-Type: text/plain; charset=utf-8

public-read
--7005673b2b0941909024b72cb0adf66c
Content-Disposition: form-data; name="Content-Type"
Content-Type: text/plain; charset=utf-8

application/octet-stream
--7005673b2b0941909024b72cb0adf66c
Content-Disposition: form-data; name="success_action_status"
Content-Type: text/plain; charset=utf-8

201
--7005673b2b0941909024b72cb0adf66c--