Click here to Skip to main content
15,889,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this simple sript:

i get this error when i run it:
OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

What I have tried:

def startproxy():
    PORT = 8000

    Handler = http.server.SimpleHTTPRequestHandler

    httpd = socketserver.TCPServer(("", PORT), Handler)

    httpd.serve_forever()
Posted
Updated 4-Apr-18 21:15pm

1 solution

Python
httpd.serve_forever()
Once started, the service will run for ever until you shut down your session. When starting another instance of the script, the running service has still opened the listening port so that trying to open it is refused with the error 10048 / WSAEADDRINUSE.

If you want to execute the script again you have to signal the running service to stop and close the socket. This requires implementing your own version of serve_forever() which can leave the service loop upon some kind of signal and close socket. See also this SO thread: python - How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass? - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900