Python CGI error ? java script error?

I’m a novice developer who wants to make a chatbot.
but my chat bot is not working TT

I think code can’t get the Python file from html.

#!/usr/bin/env python3
#html에서 입력할시 실행된다.
import cgi#웹 관련 라이브러리
import codecs
import urllib.request
from konlpy.tag import Twitter
import os, re, json, random



dict_file = "chatbot-data.json"
dic = {}
# 입력 양식의 글자 추출하기 --- (※1)
form = cgi.FieldStorage() # 웹에서 입력값을 받아 form 의 내용을
# form 이라는 변수에 저장함

# 메인 처리 --- (※2)
def main():
    m = form.getvalue("m", default="")
    if   m == "" : 
        show_form()#웹브라우저의 HTML출력
    elif m == "say" : 
        api_say()#그에 맞는 답하기

# 사용자의 입력에 응답하기 --- (※3)
def api_say():
    print("Content-Type: text/plain; charset=ANSI")
    print("")
    txt = form.getvalue("txt", default="")
    if txt == "": return
    res = make_reply(txt)#마르코프체인
    print("response")

# 입력 양식 출력하기 --- (※4)
def show_form():
    print("Content-Type: text/html; charset=ANSI")
    print("")
    print("""
    <html><meta charset="ANSI"><body>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <style>
        h1   { background-color: #ffe0e0; }
        div  { padding:10px; }
        span { border-radius: 10px; background-color: #ffe0e0; padding:8px; }
        .bot { text-align: left; }
        .usr { text-align: right; }
    </style>
    <h1>대화하기</h1>
    <div id="chat"></div>
    <div class='usr'><input id="txt" size="40">
    <button onclick="say()">전송</button></div>
    <script>
    var url = "http://localhost:8080/cgi-bin/intergrate.py";
    function say() {
      var txt = $('#txt').val();
      $.get(url, {"m":"say","txt":txt},
        function(res) {
          var html = "<div class='usr'><span>" + esc(txt) +
            "</span>: 나</div><div class='bot'> 봇:<span>" + 
            esc(res) + "</span></div>";
          $('#chat').html($('#chat').html()+html);
          $('#txt').val('').focus();
        });
    }
    function esc(s) {
        return s.replace('&', '&amp;').replace('<','&lt;')
                .replace('>', '&gt;');
    }
    </script></body></html>
    """)

this is my code
This code does not include a generation sentence code

For testing, the function api_say() returned “response”.

What’s wrong with this???

I see two issues here:

  1. The main() function isn’t called anywhere. But you still got the form, so maybe some framework does that for you?
  2. This line:

There is no make_reply() function in your script, so this will fail. Which means that the next line that would send “response” is never executed.

… or you need something like:

print(res)

instead of the line

print("response")