CherryPy Hello World error
Asked Answered
S

10

13

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?

Superficial answered 20/4, 2009 at 9:36 Comment(1)
I've faced this problem before. I hope this question will help someone.Damnation
I
7

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.

Infusive answered 20/4, 2009 at 9:57 Comment(0)
O
9

If you are trying to deploy CherryPy on Heroku, where you cannot use the loopback to check whether you have really opened a port, then you need to simply disable CherryPy's wait_for_occupied_port() function so that CherryPy's self-consistency check does not decide that it has, in fact, failed to start. Here are the three lines that I use to fix CherryPy so that it runs on Heroku:

    from cherrypy.process import servers
    def fake_wait_for_occupied_port(host, port): return
    servers.wait_for_occupied_port = fake_wait_for_occupied_port
Oddson answered 14/2, 2012 at 3:28 Comment(4)
While extremely useful this answer really doesn't belong here since it has very little to do with the OP's original question. In this case it's more appropriate to ask a more detailed and specific question to your very valuable answer, then of course, answer it :). I realize others have similar answers to this question here... but it's more of a thread hijack then anything.Antirrhinum
My answer involves running that exact script and getting that exact error. I fail to see how that has "very little to do" with the question. You can see from @laurasia's answer that others think my answer relevant to this question as well.Oddson
Yeah, just confirmed I do get the IOError and ChannelFailures: IOError, sometimes, and sometimes I just get SIGTERM. So, you are right, I was wrong about the "very little to do" comment. The lack of the error sometimes was the cause of my confusion. I still would lean slightly towards a new thread though ;)Antirrhinum
Great! Mokeypatch soultion ---> Also work if you doing MASQUERADE in iptables!Lobbyist
I
7

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.

Infusive answered 20/4, 2009 at 9:57 Comment(0)
M
3

As Jason R. Coombs wrote there is a problem with disabled loopback device. heroku.com has loopback disabled therefore CherryPy will crash. I filed a bug for this.

Update: Reported as resolved.

Milky answered 28/10, 2011 at 20:25 Comment(0)
P
2

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.

Puttee answered 29/4, 2009 at 20:5 Comment(1)
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.Puttee
E
2

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.

Update: CherryPy 3.2.3 has a fix for this particular issue. Until 3.2.3 is released, development builds are available on the CherryPy project downloads.

Extraterrestrial answered 19/7, 2010 at 15:3 Comment(0)
D
1
  • 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.
Damnation answered 29/4, 2009 at 16:13 Comment(0)
S
1

If you're on OS X, try calling:

sudo lsof -i :8080

which will tell you the process using that port.

Signalman answered 4/3, 2016 at 13:58 Comment(0)
I
0

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.

Impoverish answered 28/6, 2009 at 23:44 Comment(0)
C
0

I had the same problem when running CherryPy 3.2.2 on my Win7 PC with Python 3.3 The server would start normally and then would crash in about a couple of minutes.

I've applied the patch from CherryPy 3.2.3 laurasia mentioned. But it didn't help.

So I had to comment out the lines raising the error at the very end of python\Lib\site-packages\cherrypy\process\servers.py to prevent the server from dying:

...
#    if host == client_host(host):
#        raise IOError("Port %r not bound on %r" % (port, host))
...
Cockboat answered 11/4, 2013 at 19:52 Comment(1)
I had the same problem, with the same setup, only on OS X. I just commented out the very last line in the same file. raise IOError("Port %r not bound on %r" % (port, host))Benzoic
E
0

Windows 10

If you get a python exception printed to stdio that 8080 is not free on 127.0.0.1, then what you do is this:

netstat -o -a

at the windows command prompt. Doing netstat -o alone will give you an incorrect PID.

Look for 8080 in the address string in the first column. Once found, go horizontally over to the last column which is the PID (process ID).

Now to kill a process, I use kill <PID> which is part of an mysys install. I found that out by doing where kill on my system.

Thus all together:

netstat -o -a
[find PID then hit ctrl-c to stop netstat]
kill 13164  

where 13164 is an example PID found in the first step.

If you do not have mysys installed, then install it or else look up how to kill a process by its PID on windows.

Enthrone answered 27/9, 2020 at 2:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.