用python http.sever实现web服务时,绑定端口由于强制退出导致再次启动服务报错:
self.socket.bind(self.server_address)
OSError: [Errno 48] Address already in use
临时解决办法:
查找端口被占用的进程,然后强制结束
lsof -i:9090
然后kill对应的进程
#--coding:utf-8--
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
import socket
class CarServer(BaseHTTPRequestHandler):
def get_host_ip(self):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write("Hello World !".encode())
if name == "main":
socket.set
myServer = HTTPServer(("192.168.1.101", 9090), CarServer)
print(time.asctime(), "Server Starts - %s:%s" % ("a","b"))
try:
myServer.serve_forever()
except KeyboardInterrupt:
pass