title: How do I send Server Log to Client through http.server Python?
body: <p>As the question, I now creating a <code>simple http.server with Python</code> and I have to send information about request like <code>Client IP</code>, <code>login time of client</code>, <code>method GET/POST</code>, <code>HTTP header</code>, <code>HTTP body</code> to Client and display it on Frontend. But I don't know how to send and how to get that information to send ? Please help me, thanks
  This is my server code:</p>
  <pre><code>from http.server import BaseHTTPRequestHandler, HTTPServer
  import os
  import cgi
  
  from supervisor.medusa.auth_handler import get_header
  
  from database.db import create_table, signup, check_login
  from random import randint
  from datetime import datetime
  import logging
  
  islogin = False
  
  def read_html_template(path):
      try:
          with open(path) as f:
              file = f.read()
      except Exception as e:
          file = e
      return file
  
  class handler(BaseHTTPRequestHandler):
      def gen_token(self):
          return &quot;&quot;.join(str(randint(1, 9)) for _ in range(25))
      def get_Ip_addr(self):
          return self.client_address[0]
      def get_header(self):
          return logging.error(self.headers)
      def get_time(self):
          now = datetime.now()
          return now.strftime(&quot;%d/%m/%Y %H:%M:%S&quot;)
      def data_to_send(self):
          login_time = self.get_time()
          header_data = self.get_header()
          ip_client = self.get_Ip_addr()
          data = ('{&quot;IP_Client&quot;: '+ str(ip_client) + ', &quot;HTTP_Header&quot;: ' + str(header_data) + ', &quot;Login_Time&quot;: '+ str(login_time) + '}')
          return data
      def do_GET(self):
          if self.path == '/':
              self.path = './src/html/index.html'
          elif self.path == '/login':
              self.path = './src/html/Login.html'
          elif self.path == '/signup':
              self.path = './src/html/Signup.html'
          elif self.path == '/forgotpwd':
              self.path = './src/html/ForgotPwd.html'
          elif self.path == '/home' and islogin == True:
              self.path = './src/html/singnedIn.html'
          try:
              split_path = os.path.splitext(self.path)
              request_extension = split_path[1]
              if request_extension != &quot;.py&quot;:
                  f = read_html_template(self.path)
                  self.send_response(200)
                  self.end_headers()
                  self.wfile.write(bytes(f, 'utf-8'))
              else:
                  f = &quot;File not found&quot;
                  self.send_error(404,f)
          except:
              f = &quot;File not found&quot;
              self.send_error(404,f)
  
  with HTTPServer(('', 8000), handler) as server:
      server.serve_forever()
  </code></pre>
  <p>My idea is write data to a json file and send it to client but 2 things I don't know is</p>
  <p><code>How to send json file ?</code> and
  <code>How to get data and write it to json file ?</code></p>