0

我正在尝试在 python 中编写一个基本的 WEB 服务器,当接收到以下请求时: \sth?input=a 它发送以下格式的 JSON 结果:

{
output:[list,of,words]
}

我不知道如何在计算后发送响应,以及如何将其放入 JSON 格式。这是我对 do_GET 的实现:

class MyServer(BaseHTTPRequestHandler):
    def do_GET(self):
        my_path = self.path.split("?")
        my_url = my_path[0]
        self.send_response(200)
        self.send_header("Content-type", "text")
        self.end_headers()
        if my_url == "\sth":
            word_to_process = my_path[1].split("=")[1]
            res = similar(word_to_process)

res是我的结果,我想以 JSON 格式发送它作为响应,我该怎么做?

4

0 回答 0