views:

795

answers:

5

When I am running CherryPy Hello World:

import cherrypy

class HelloWorld:
    def index(self):
        return "Hello world!"
    index.exposed = True

cherrypy.config.update({'server.socket_port': 8080,})
cherrypy.quickstart(HelloWorld())

... I get this: IOError: Port 8080 not bound on 'localhost'. What could it be?

+1  A: 

You've probably got something else listening on that port.

On Linux do:

netstat -pnl | grep 8080

And see what process is listening on 8080

On Windows use something like TCPView to do the same.

Douglas Leeder
+1  A: 
  • Use it on different port (8000 for example)
  • Read about ConfigApi (once again)
  • Try latest version not 3.0
  • Also this can be caused by some Windows firewall (Eset smart security or maybe other). So just use it on different port.
Oleksandr Bolotov
A: 

I think I had a similar problem when I started using CherryPy... But I can't remember exactly what it was... But the fix involved using a config file instead of passing the configs by hand:

MyProj.conf:

[global]
server.socket_host = "127.0.0.1"
server.socket_port = 8080
server.thread_pool = 10

MyProj.py

import os
import cherrypy

class HelloWorld:
    def index(self):
        return "Hello world!"
    index.exposed = True

# Assumes the config file is in the directory as the source.    
conf_path = os.path.dirname(os.path.abspath(__file__))
conf_path = os.path.join(conf_path, "MyProj.conf")
cherrypy.config.update(conf_path)
cherrypy.quickstart(HelloWorld())

This definitely works here.
I'm using Python 2.6.1 and CherryPy 3.1.1 and I run the script with -W ignore:

c:\My_path> python -W ignore MyProj.py

If you're under *nix, you should put the -W ignore in the #! comment at the top of the file.

Joce
The "-W ignore" is because CherryPy 3.1.1 isn't fully Python 2.6 ready; but it's still good enough for our internal needs here.
Joce
A: 

AVG Anti-Virus was causing this problem for me. Uninstalling AVG (far from ideal) did the trick. I suspect the link scanner that I couldn't disable.

Glen Richards
A: 

I ran into this problem yesterday on an Ubuntu Linux server. I spent a couple of hours trying to track down the bug in the CherryPy code before I realized that the error message is very generic. It will give this error message even if the host doesn't own the IP address to which the server is attempting to bind. In my case, the loopback interface (lo, 127.0.0.1) was disabled. Thus, even if I set server.socket_host='0.0.0.0', the attempt to check the port, wait_for_occupied_port, would fail (as it assumes, reasonably, that the loopback interface is always available). After re-enabling the loopback interface, the CherryPy server would start up normally.

Jason R. Coombs