twisted.internet.error.CannotListenError: Couldn't listen on any:80: [Errno 13] Permission denied

tutormike picture tutormike · Dec 15, 2012 · Viewed 7.5k times · Source

I am currently working on a project to create a TCP server on mac os mountain lion. I wrote a script called: Server.py

Within this python script, I used twisted to listen upon port 80 as shown below:

reactor.listenTCP(80, factory)
reactor.run()

How ever I am getting errors as such:

File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/posixbase.py", line 436, in listenTCP
    p.startListening()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/tcp.py", line 641, in startListening
    raise CannotListenError, (self.interface, self.port, le)
twisted.internet.error.CannotListenError: Couldn't listen on any:80: [Errno 13] Permission denied.

I am thinking is it because the tcp.py script has the wrong permission for admin user? or is there a way to set permission on the port < 1024? (To change the permission, how would it affects the security of such a server?)

Any better solutions is apprieciated.

Answer

Qasim Ali Khan picture Qasim Ali Khan · Mar 23, 2013

Just go to the terminal and type sudo python server.py. Now it will ask password, type your password. Your problem will be solved. Happy coding