socket.error: [Errno 48] Address already in use

后端 未结 10 2266
小鲜肉
小鲜肉 2020-11-29 14:33

I\'m trying to set up a server with python from mac terminal.

I navigate to folder location an use:

python -m SimpleHTTPServer

Bu

10条回答
  •  自闭症患者
    2020-11-29 15:03

    You can allow the server to reuse an address with allow_reuse_address.

    Whether the server will allow the reuse of an address. This defaults to False, and can be set in subclasses to change the policy.

    import SimpleHTTPServer, SocketServer
    PORT = 8000
    httpd = SocketServer.TCPServer(("", PORT), SimpleHTTPServer.SimpleHTTPRequestHandler)
    httpd.allow_reuse_address = True
    print "Serving at port", PORT
    httpd.serve_forever()
    

提交回复
热议问题