title: How to save a text file received in a POST request using python
body: <pre><code>from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
  import SocketServer
  
  
  class S(BaseHTTPRequestHandler):
      def _set_headers(self):
          self.send_response(200)
          self.send_header('Content-type', 'text/html')
          self.end_headers()
  
      def do_POST(self):
          data = self.rfile.read(int(self.headers.getheader('content-length')))
          print data
          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;")
  
  def run(server_class=HTTPServer, handler_class=S, port=8080):
      server_address = ('localhost', port)
      httpd = server_class(server_address, handler_class)
      print 'Starting server'
      httpd.serve_forever()
  
  run()    
  </code></pre>
  
  <p>This is my server code. The post requests I receive contain a text file and other key:value pairs.This prints the whole content including the content of the text file. How can I save that text file on my hard drive..?
  Any guidance is appreciated.</p>