title: How does rfile.read() work?
body: <p>I'm sending a text file with a string in a python script via POST to my server:</p>
  
  <pre><code>fo = open('data'.txt','a')
  fo.write("hi, this is my testing data")
  fo.close()
  
  with open('data.txt', 'rb') as f:
      r = requests.post("http://XXX.XX.X.X", data = {'data.txt':f})
      f.close()
  </code></pre>
  
  <p>And receiving and handling it here in my server handler script, built off an example found online:</p>
  
  <pre><code>def do_POST(self):
      data = self.rfile.read(int(self.headers.getheader('Content-Length')))
      empty = [data]
      with open('processing.txt', 'wb') as file:
          for item in empty:
              file.write("%s\n" % item)
  
      file.close()
      self._set_headers()
      self.wfile.write("&lt;html&gt;&lt;body&gt;&lt;h1&gt;POST!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;")
  </code></pre>
  
  <p>My question is, how does:</p>
  
  <pre><code>self.rfile.read(int(self.headers.getheader('Content-Length')))
  </code></pre>
  
  <p>take the length of my data (an integer, # of bytes/characters) and read my file? I am confused how it knows what my data contains. What is going on behind the scenes with HTTP?</p>
  
  <p>It outputs <code>data.txt=hi%2C+this+is+my+testing+data</code></p>
  
  <p>to my processing.txt, but I am expecting <code>"hi this is my testing data"</code></p>
  
  <p>I tried but failed to find documentation for what exactly rfile.read() does, and if simply finding that answers my question I'd appreciate it, and I could just delete this question.</p>