views:

324

answers:

3

I am having an issue with cherrypy that looks solved, but doesn't work. I can only bind on localhost or 127.0.0.1. Windows XP Home and Mac OS X (linux untested), cherrypy 3.1.2, python 2.5.4. This is the end of my app:

global_conf = {
       'global':    { 'server.environment= "production"'
                      'engine.autoreload_on : True'
                      'engine.autoreload_frequency = 5 '
                      'server.socket_host': '0.0.0.0',
                      'server.socket_port': 8080}
    }
cherrypy.config.update(global_conf)
cherrypy.tree.mount(home, '/', config = application_conf)
cherrypy.engine.start()
+4  A: 

huh, you're doing something wrong with your dict:

>>> global_conf = {
...        'global':    { 'server.environment= "production"'
...                       'engine.autoreload_on : True'
...                       'engine.autoreload_frequency = 5 '
...                       'server.socket_host': '0.0.0.0',
...                       'server.socket_port': 8080}
...     }
>>> print global_conf
{'global': 
   {'server.environment= "production"engine.autoreload_on : Trueengine.autoreload_frequency = 5 server.socket_host': '0.0.0.0',
    'server.socket_port': 8080}
}

More specifically, there are commas and colons missing from your dict definiton. Each key/value pair must have a colon, and they are separated with commas. Something like this might work:

global_conf = {
       'global':    { 'server.environment': 'production',
                      'engine.autoreload_on': True,
                      'engine.autoreload_frequency': 5,
                      'server.socket_host': '0.0.0.0',
                      'server.socket_port': 8080,
                    }
              }

Check python dictionary documentation for more info.

nosklo
A: 

Yeah, thanks! I found the comma issues sometime after I posted this, but could never get it to work. Looked closely at the server output and it was just never changing. I ended up moving the stuff to a file because the file format for global configuration was much better documented. See: differences between your server.environment and mine. I'm admittedly novice and some of this stuff I just end up hammering into shape because some things that are obvious to more experienced programmers are not that obvious to me.

Thanks a bunch, though.

twomonkeysayoyo
A: 

If you're using a dual-stack OS, it may be that localhost is resolving to ::1 (the IPv6 localhost) and not 127.0.0.1 (the IPv4 localhost). Try accessing the server using http://127.0.0.1:8080.

Also, if you're using an dual-stack capable OS, you can set server.socket_host to '::', and it will listen on all addresses in IPv6 and IPv4.

Jason R. Coombs