Looks like while terminating / testing the script, your process might not be terminated properly and some part of it still running, occupying the same port. Here is a quick solution without modifying anything in your script. Look if any process with the same name is already running by issuing following command. ps aux | grep <script-name> If yes, kill it by sudo kill -9 <process-id> Restart the script. There is another way as per this [link][1]. While creating socket, make use of follwoing option. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) By enabling this option, socket will allow reusing the same address even if it's not terminated properly. Hope it helps. [1]: https://stackoverflow.com/questions/4465959/python-errno-98-address-already-in-use?lq=1