title: How to read, process variable POST, Python HTTP Server
body: <p><strong>Server code</strong>  </p>
  
  <pre><code>#!/usr/bin/env python
  import BaseHTTPServer
  from BaseHTTPServer import BaseHTTPRequestHandler
  import SocketServer
  import urlparse
  import cgitb
  import cgi
  from cgi import parse_header, parse_multipart
  
  
  class S(BaseHTTPRequestHandler):
   def _set_headers(self):
    self.send_response(200)
    self.send_header('Content-type', 'text/html')
    self.end_headers()
  
   def do_GET(self):
     self._set_headers()
     self.wfile.write("&lt;html&gt;&lt;body&gt;&lt;h1&gt;hi!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;")
  
   def do_HEAD(self):
     self._set_headers()
  
   def do_POST(self):
    ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
    if ctype == 'multipart/form-data':
     postvars = cgi.parse_multipart(self.rfile, pdict)
    elif ctype == 'application/x-www-form-urlencoded':
     length = int(self.headers.getheader('content-length'))
     postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
    else:
     postvars = {}
  
  def run(server_class=BaseHTTPServer.HTTPServer, handler_class=S, port=80):
   server_address = ('', port)
   httpd = server_class(server_address, handler_class)
   print 'Starting httpd...'
   httpd.serve_forever()
  
  if __name__ == "__main__":
  
          run()
  </code></pre>
  
  <p><strong>Clinet</strong></p>
  
  <p>Client send POST request over program Postman.</p>
  
  <p>GET works. </p>
  
  <p>Post is does not work . This is Error on server when I send request </p>
  
  <p><a href="http://192.168.2.108?var1=value" rel="nofollow noreferrer">http://192.168.2.108?var1=value</a></p>
  
  <p><strong>ERROR ON SERVER</strong></p>
  
  <blockquote>
    <p>Exception happened during processing of request from ('192.168.2.107',
    49629) Traceback (most recent call last):   File
    "/usr/lib/python2.7/SocketServer.py", line 295, in
    _handle_request_noblock
        self.process_request(request, client_address)   File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
        self.finish_request(request, client_address)   File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
        self.RequestHandlerClass(request, client_address, self)   File "/usr/lib/python2.7/SocketServer.py", line 655, in <strong>init</strong>
        self.handle()   File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
        self.handle_one_request()   File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in
    handle_one_request
        method()   File "server.py", line 37, in do_POST
        ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))   File
    "/usr/lib/python2.7/cgi.py", line 309, in parse_header
        parts = _parseparam(';' + line) TypeError: cannot concatenate 'str' and 'NoneType' objects</p>
  </blockquote>