Get the App
SLTechnology News&Howtos  ›  Development  › 

How does python solve the OSError: Address already in use problem

Shulou Source: shulou.com Published: 2022-06-03 04:31:05 10月03日 Update

Editor to share with you how python to solve the OSError: Address already in use problem, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

When implementing the web service with python http.sever, the binding port reports an error when starting the service again due to forced exit:

Self.socket.bind (self.server_address)

OSError: [Errno 48] Address already in use

Temporary solution:

Find the process in which the port is occupied, and then force the end

Lsof-iPUR 9090

Then the corresponding process of 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 -% SVA% s"% ("a", "b"))

Try: myServer.serve_forever () except KeyboardInterrupt: pass these are all the contents of the article "how python solves the OSError: Address already in use problem". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Articles questions content ports processes enforcement services not much again methods most more knowledge industry information information channels channels references learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information OPPO Reno macOS Huawei MariaDB