Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report