使用python监听端口8080上的http请求和端口4443上的https请求

时间:2018-10-25 17:31:17

标签: python http https server request

所以我正在创建一个程序,该程序在4443端口侦听https请求并返回Hello,在8080端口侦听http请求并返回world

45

但是我什至无法启动服务器 给出错误

import http.server
import _thread,time
def init_server(http):
    server_class = http.server.HTTPServer
    if http:
        httpd = server_class(("0.0.0.0", 8080), MyHandler)
    else: # https
        httpd = server_class(("0.0.0.0", 4443), MyHandler)
        httpd.socket = ssl.wrap_socket (httpd.socket, certfile='./server.pem', server_side=True)
    httpd.serve_forever()
    httpd.server_close()
VERBOSE = "True"
_thread.start_new_thread(init_server, (True, ))
_thread.start_new_thread(init_server, (False, ))
while 1:
time.sleep(10) 

有人可以帮我做同样的代码吗。我在这方面有点新手 谢谢

0 个答案:

没有答案