title: Send a .csv file using Requests 2.2.1 in Python 2.7.6
body: <p>I have to send a small .csv file to a partner server using the API they provide. I'm using Requests 2.2.1 in Python 2.7.6 and I have a working example in PHP. I can't put much more information but I was wondering if somebody could see what is the issue based on the output of my erroneous code (in Python) and the output of the working code (in PHP)</p>
  
  <p>This is a trimmed down version of what I have, based on the doc of Requests to send a file (<a href="http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file" rel="nofollow">POST a Multipart-Encoded File</a>)</p>
  
  <pre><code>import os
  import requests
  
  filecontent=open(filename,'r').read()
  r=requests.post( url
                 , data={'sessionId':sessionId, 'source':'Neurotracker'}
                 , files={'files': (os.path.basename(filename), filecontent, 'application/octet-stream')} )
  print('response text=[{}]'.format(r.text))
  </code></pre>
  
  <p>This is the kind of output I get</p>
  
  <pre><code>response text=[{"status":"error","error":{"descr":"Unknown error in FACTS file save path - sites\/default\/files\/facts\/csv\/2015\/04 _FILES is = 
  Array
  (
      [files] =&gt; Array
          (
              [name] =&gt; 344_2015-04-08T145040.csv
              [type] =&gt; application\/octet-stream
              [tmp_name] =&gt; \/tmp\/phpW6jG0w
              [error] =&gt; 0
              [size] =&gt; 223
          )
  )","number":106}}]
  </code></pre>
  
  <p>This is a working example in PHP</p>
  
  <pre><code>$post = array(
      'sessionId' =&gt; $sessionId,
      'source' =&gt; 'Polar',
      'files[factfile]' =&gt; '@' . $file_name_with_full_path
  );
  
  
  $ch = curl_init();
  // May want to have error checking code for the init. 
  // 
  // note order is important. POST opt sett must come before POSTFIELDs, according to docs...
  curl_setopt($ch, CURLOPT_URL, $target_url);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
  $result = curl_exec($ch);
  // You should have some error handling for the result. One option is to print_r($result,true); dpm($result);
  curl_close($ch);
  </code></pre>
  
  <p>And here would be the output of a good file upload</p>
  
  <pre><code>Array
  (
      [files] =\x3e Array
          (
              [name] =\x3e Array
                  (
                      [factfile] =\x3e 344_2015-04-08T145040.csv
                  )
              [type] =\x3e Array
                  (
                      [factfile] =\x3e application/octet-stream
                  )
              [tmp_name] =\x3e Array
                  (
                      [factfile] =\x3e /Applications/MAMP/tmp/php/phpQfSVVK
                  )
              [error] =\x3e Array
                  (
                      [factfile] =\x3e 0
                  )
              [size] =\x3e Array
                  (
                      [factfile] =\x3e 223
                  )
          )
  )
  </code></pre>
  
  <p>I've noticed that all sub-keys of [files] are arrays in the output of a good file upload while mine isn't. So I've tried the way to send multiple files using Requests (<a href="http://docs.python-requests.org/en/latest/user/advanced/#post-multiple-multipart-encoded-files" rel="nofollow">POST Multiple Multipart-Encoded Files</a>)</p>
  
  <pre><code>r=requests.post( url
                 , data=payload
                 , files=[('files', (os.path.basename(filename), filecontent, 'application/octet-stream'))] );
  </code></pre>
  
  <p>Without more luck.</p>
  
  <p>I have the feeling that Requests might not be able to achieve a file upload in the expected format by the API; that would be with arrays in the sub-keys of [files]. </p>