I am running below code as root and using python2.6.1, platform is linux
>>> import socket
>>> serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> serversocket.bind((socket.gethostname(), 80))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in bind
socket.error: [Errno 1] Operation not permitted
How to solve this problem
There are several possibilities.
Note that the port is not immediately available after the socket is closed (server having been killed). If you want to be sure that processes that don't exist anymore cannot be blocking the port from reuse, issue:
serversocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
before binding it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With