How to add form-data variables to a post request using python requests module?
Question: I am trying to create a command line utility to upload files to tempsend.com
using Python's `requests` module.

I have read the docs and it seems like what I am trying to accomplish should
be quite easy, but I can't get it to successfully post the file.

Here are some of the formats I have tried:

    
    
    >>> import requests
    >>> url = "http://tempsend.com/send"
    >>> payload = {'file': open('happy.txt', 'rb'), 'expire': '2678400'}
    >>> r = requests.post(url, data=payload)
    >>> r.url
    u'http://tempsend.com/error-nopostdata'
    

and:

    
    
    >>> files = {'file': open('happy.txt', 'rb'), 'expire' : '2678400'}
    >>> r = requests.post(url, files=files)
    >>> r.url
    u'http://tempsend.com/error-badsecondsvalue'
    

It looks like the `'expire'` field is not recognized.

I think this is what a valid raw request should look like:

    
    
    POST /send HTTP/1.1
    Host: tempsend.com
    User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-gb,en;q=0.5
    Accept-Encoding: gzip, deflate
    Referer: http://tempsend.com/
    Cookie: __utma=151760572.1993029721.1402528667.1402603529.1402606574.3;         __utmz=151760572.1402528667.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);     __utmb=151760572.2.10.1402606574; __utmc=151760572
    Connection: keep-alive
    Content-Type: multipart/form-data;     boundary=---------------------------18953598303296896262036228879
    Content-Length: 835112
    
    -----------------------------18953598303296896262036228879
    Content-Disposition: form-data; name="file"; filename="modules.alias"
    Content-Type: application/octet-stream
    
    # Aliases extracted from modules themselves.
    alias aes-asm aes_x86_64
    alias aes aes_x86_64
    alias camellia-asm camellia_x86_64
    <blablablablablablablabla>
    
    
    -----------------------------18953598303296896262036228879
    Content-Disposition: form-data; name="expire"
    
    2678400
    -----------------------------18953598303296896262036228879--
    


Answer: 
    >>> import requests
    >>> files = {'file': open('happy.txt', 'rb')}
    >>> url = "http://tempsend.com/send"
    >>> r = requests.post(url, data={'expire':'2678400'}, files=files)
    >>> r.url
    u'http://tempsend.com/36DCF220A3'
    >>> 
    

I found the answer 5 minutes after asking the question.. Typical!

