title: python requests - POST Multipart/form-data without filename in HTTP request
body: <p>I am trying to replicate the following POST request using the requests module in python:</p>
  
  <pre><code>POST /example/asdfas HTTP/1.1
  Host: example.com
  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Language: en-US,en;q=0.5
  Accept-Encoding: gzip, deflate
  Connection: keep-alive
  Content-Type: multipart/form-data; boundary=---------------------------241652170216373
  Content-Length: 279
  
  -----------------------------241652170216373
  Content-Disposition: form-data; name="value_1"
  
  12345
  -----------------------------241652170216373
  Content-Disposition: form-data; name="value_2"
  
  67890
  -----------------------------241652170216373--
  </code></pre>
  
  <p>The documentation for <a href="http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file" rel="noreferrer">requests</a> suggests that the files argument should be used.</p>
  
  <p>When I attempt the following call:</p>
  
  <pre><code>import requests
  requests.post('http://example.com/example/asdfas', files={'value_1': '12345', 
                                                            'value_2': '67890'})
  </code></pre>
  
  <p>I get the following HTTP request:</p>
  
  <pre><code>'Accept': '*/*', 
  'Accept-Encoding': 'gzip, deflate, compress', 
  'Content-Length': '264', 
  'User-Agent': 'python-requests/2.2.1 CPython/3.3.2 Windows/7', 
  'Content-Type': 'multipart/form-data; boundary=273f13699c02429db4eb95c97f757d38'
  --273f13699c02429db4eb95c97f757d38
  Content-Disposition: form-data; name="value_1"; filename="value_1"
  
  12345
  --273f13699c02429db4eb95c97f757d38
  Content-Disposition: form-data; name="value_2"; filename="value_2"
  
  67890
  --273f13699c02429db4eb95c97f757d38--
  </code></pre>
  
  <p>I have also tried to use the data argument:</p>
  
  <pre><code>import requests
  requests.post('http://example.com/example/asdfas', data={'value_1': '12345', 
                                                           'value_2': '67890'})
  </code></pre>
  
  <p>resulting in the following HTTP request:</p>
  
  <pre><code>'Content-Type': 'application/x-www-form-urlencoded', 
  'Content-Length': '27', 
  'User-Agent': 'python-requests/2.2.1 CPython/3.3.2 Windows/7', 
  'Accept': '*/*', 
  'Accept-Encoding': 'gzip, deflate, compress'
  value_2=67890&amp;value_1=12345
  </code></pre>
  
  <p>The issue I'm having is that using the files argument results in a call that the server doesn't recognize, presumably due to the unexpected "filename" information sent in the HTTP request. Using the data argument sends the wrong Content-Type header. </p>
  
  <p>The first request is known to be working on the server I wish to send the request to - what is the correct function call to identically replicate the first HTTP request?</p>
  
  <p>Edit:
  Sample HTML form to replicate the working request:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action="http://example.com/example/asdfas" method="post" enctype="multipart/form-data"&gt;
          &lt;label for="v1"&gt;Value 1&lt;/label&gt;
          &lt;input id="v1" type="text" name="value_1"&gt;
          &lt;label for="v2"&gt;Value 2&lt;/label&gt;
          &lt;input id="v2" type="text" name="value_2"&gt;
          &lt;input type="submit"&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>