title: How to add form-data variables to a post request using python requests module?
body: <p>I am trying to create a command line utility to upload files to tempsend.com using Python's <code>requests</code> module.</p>
  
  <p>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.</p>
  
  <p>Here are some of the formats I have tried:</p>
  
  <pre><code>&gt;&gt;&gt; import requests
  &gt;&gt;&gt; url = "http://tempsend.com/send"
  &gt;&gt;&gt; payload = {'file': open('happy.txt', 'rb'), 'expire': '2678400'}
  &gt;&gt;&gt; r = requests.post(url, data=payload)
  &gt;&gt;&gt; r.url
  u'http://tempsend.com/error-nopostdata'
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>&gt;&gt;&gt; files = {'file': open('happy.txt', 'rb'), 'expire' : '2678400'}
  &gt;&gt;&gt; r = requests.post(url, files=files)
  &gt;&gt;&gt; r.url
  u'http://tempsend.com/error-badsecondsvalue'
  </code></pre>
  
  <p>It looks like the <code>'expire'</code> field is not recognized.</p>
  
  <p>I think this is what a valid raw request should look like:</p>
  
  <pre><code>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
  &lt;blablablablablablablabla&gt;
  
  
  -----------------------------18953598303296896262036228879
  Content-Disposition: form-data; name="expire"
  
  2678400
  -----------------------------18953598303296896262036228879--
  </code></pre>