title: Why the Python BaseHttpServer server stops after execution?
body: <p>I am trying to develop application which will have a Python Webserver. Everything works as expected, but after executing the logic(by using do_GET and do_POST methods) the server just stops and a <strong>connection reset</strong> page is visible. Below is the screenshot of the page:</p>
  
  <p><a href="https://i.stack.imgur.com/6nZP3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6nZP3.png" alt="enter image description here"></a></p>
  
  <p>And below is the Python webserver code:</p>
  
  <pre><code> from http.server import BaseHTTPRequestHandler, HTTPServer
  
   # HTTPRequestHandler class
   class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
  
   # GET
   def do_GET(self):
      # Send response status code
      self.send_response(200)
  
      # Send headers
      self.send_header('Content-type','text/html')
      self.end_headers()
      file = "./some2.html"
      file2 = open(file,"r")
      # Write content as utf-8 data
      self.wfile.write(bytes(file2.read(), "utf8"))
      #return
  
   def do_POST(self):
      content_len = int(self.headers.get('content-length', 0))
      post_body = self.rfile.read(content_len)
      print(post_body)
      with open("rsmsg.txt","a") as f:
        f.write(str(post_body))
      print("Done storing file")  
      #return
  
   def run():
      print('starting server...')
      # Server settings
      server_address = ('192.168.10.151', 8083)
      httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
      print('running server...')
      httpd.serve_forever()
  
   run()
  </code></pre>
  
  <p>And below is the HTML code:</p>
  
  <pre><code>&lt;html&gt;
   &lt;body&gt; 
     &lt;script&gt;
       function getvalue(){
          value1 = document.getElementById("first").innerHTML
          value2 = document.getElementById("last").innerHTML
          return value1+value2
       }
     &lt;/script&gt;    
  
     &lt;form action="" method="post"&gt;
        First name:&lt;br&gt;
       &lt;input id="first" type="text" name="firstname"&gt;
       &lt;br&gt;
       Last name:&lt;br&gt;
       &lt;input id = "last" type="text" name="lastname"&gt;
       &lt;br&gt;&lt;br&gt;
       &lt;button type = "submit" onclick=getvalue()&gt;Press it to store data on    server&lt;/button&gt;
     &lt;/form&gt; 
  
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>After pressing button the data in the <code>input id="first"</code> and <code>input id="last"</code> will given to server. But after pressing why the <strong>The connection reset</strong> page is displayed? and how do I prevent it?</p>
  
  <p><strong>UPDATE</strong>
  After debugging I understood that in the JS in HTML code, the <code>value1</code> and <code>value2</code> are null but still I am getting data! but with field names. Example:
  firstname=Nick&amp;lastname=A. I thought this might be the reason for the connection reset page hence updated the question.</p>
  
  <p><strong>Terminal Output</strong>
  <a href="https://i.stack.imgur.com/RZgpZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RZgpZ.png" alt="The output seen on terminal"></a></p>