Problems with running cherrypy's hello world example
Asked Answered
W

1

9

I'm trying to test cherrypy framework by using example from their site:

import cherrypy
class HelloWorld(object):
    def index(self):
    return "Hello World!"
    index.exposed = True

cherrypy.quickstart(HelloWorld())

When I run it I get this response in the console:

[05/Dec/2011:00:15:11] ENGINE Listening for SIGHUP.
[05/Dec/2011:00:15:11] ENGINE Listening for SIGTERM.
[05/Dec/2011:00:15:11] ENGINE Listening for SIGUSR1.
[05/Dec/2011:00:15:11] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.

[05/Dec/2011:00:15:11] ENGINE Started monitor thread '_TimeoutMonitor'.
[05/Dec/2011:00:15:11] ENGINE Started monitor thread 'Autoreloader'.
[05/Dec/2011:00:15:12] ENGINE Serving on 127.0.0.1:8080
[05/Dec/2011:00:15:12] ENGINE Bus STARTED

When running browser locally and pointig to localhost:8080 it works but to the outside world when using serverip:8080 it doesn't. Do I have to set server's ip address somewhere?

Winterize answered 5/12, 2011 at 0:27 Comment(0)
N
13

By default cherrypy.quickstart is only going to bind to localhost 127.0.0.1, which can be access from the serving computer but not from computers connected to it through the network.
If you want to be able to access the site from another computer, you need to set the configuration, like documented in here.

Here's a basic example, just changing cherrypy to bind to all network interfaces.

import cherrypy
class HelloWorld(object):
    def index(self):
        return "Hello World!"
    index.exposed = True

# bind to all IPv4 interfaces
cherrypy.config.update({'server.socket_host': '0.0.0.0'})
cherrypy.quickstart(HelloWorld())
Numbers answered 5/12, 2011 at 1:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.