Python CGI endless error

127.0.0.1 - - [11/Jul/2020 20:03:02] command: C:\Users\2포대\AppData\Local\Programs\Python\Python37\python.exe -u C:\Users\2포대\cgi-bin\chatbot.py ""
127.0.0.1 - - [11/Jul/2020 20:03:03] b'Traceback (most recent call last):\r\n  File "C:\\Users\\2\xc6\xf7\xb4\xeb\\cgi-bin\\chatbot.py", line 5, in <module>\r\n    from botengine import make_reply\r\n  File "C:\\Users\\2\xc6\xf7\xb4\xeb\\cgi-bin\\botengine.py", line 8, in <module>\r\n    okt = Okt()\r\n  File "C:\\Users\\2\xc6\xf7\xb4\xeb\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\konlpy\\tag\\_okt.py", line 95, in __init__\r\n    self.jki = OktInterfaceJavaClass()\r\n  File "C:\\Users\\2\xc6\xf7\xb4\xeb\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\jpype\\_jpackage.py", line 123, in __call__\r\n    raise TypeError("Package {0} is not Callable".format(self._name))\r\nTypeError: Package <Java package kr.lucypark.okt.OktInterface._name> is not Callable\r\n'
127.0.0.1 - - [11/Jul/2020 20:03:03] CGI script exit status 0x1

this is error code


#!/usr/bin/env python3
#html에서 입력할시 실행된다.
import cgi#웹 관련 라이브러리
from botengine import make_reply

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

# 메인 처리 --- (※2)
def main():
    m = form.getvalue("m", default="")
 
    show_form()#웹브라우저의 HTML출력

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

# 입력 양식 출력하기 --- (※4)
def show_form():
    print("Content-Type: text/html; charset=utf-8")
    print("")
    print("""
    <html><meta charset="utf-8"><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 = "./chatbot.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>
    """)

main()

this is my code

i don’t know web server well but i guess problem is cgi


and this is web

Take a look at that traceback in the server log, decoding the Python bytes object makes it a bit more readable:

>>> print(b.decode(errors='replace'))
Traceback (most recent call last):
  File "C:\Users\2����\cgi-bin\chatbot.py", line 5, in <module>
    from botengine import make_reply
  File "C:\Users\2����\cgi-bin\botengine.py", line 8, in <module>
    okt = Okt()
  File "C:\Users\2����\AppData\Local\Programs\Python\Python37\lib\site-packages\konlpy\tag\_okt.py", line 95, in __init__
    self.jki = OktInterfaceJavaClass()
  File "C:\Users\2����\AppData\Local\Programs\Python\Python37\lib\site-packages\jpype\_jpackage.py", line 123, in __call__
    raise TypeError("Package {0} is not Callable".format(self._name))
TypeError: Package <Java package kr.lucypark.okt.OktInterface._name> is not Callable

Looks like importing the botengine package fails. Not sure what’s going on with the Java stuff, maybe that module requires Jython and certain Java packages or something?

As a side note, that traceback isn’t valid utf-8 (that’s why I used errors='replace' for decoding), you might want to fix whatever locale setting is responsible for that.

1 Like