I would like to access my CherryPy site on a different computer, but I have tried the answers form here and here, but neither have worked. I am using a Mac with OSX El Capitan, Python 3.5.2, and I believe, the latest version of CherryPy. This is my current code, I do not care what the address is, just that it works. Thanks for any help!
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())
EDIT:
I can access the site from localhost:8080
127.0.0.1
and 0.0.0.0
. The console output is this:
[26/Jul/2016:19:10:26] ENGINE Listening for SIGTERM.
[26/Jul/2016:19:10:26] ENGINE Listening for SIGHUP.
[26/Jul/2016:19:10:26] ENGINE Listening for SIGUSR1.
[26/Jul/2016:19:10:27] ENGINE Bus STARTING
Warning (from warnings module):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/cherrypy/_cpchecker.py", line 105
warnings.warn(msg)
UserWarning: The Application mounted at '' has an empty config.
[26/Jul/2016:19:10:27] ENGINE Started monitor thread '_TimeoutMonitor'.
[26/Jul/2016:19:10:27] ENGINE Started monitor thread 'Autoreloader'.
[26/Jul/2016:19:10:27] ENGINE Serving on http://0.0.0.0:8080
[26/Jul/2016:19:10:27] ENGINE Bus STARTED
I run my file using IDLE, and I am not using a firewall.
The solution is mentioned in comments below the question so this answer is just for marking this question as answered.
Solution: If you want to see your cherrypy application from another computer, find out an IP address on computer where cherrypy is running, using ifconfig
on Unix/Linux or ipconfig
on Windows. Then set this IP address to your cherrypy config instead of 127.0.0.1
or 0.0.0.0
.
cherrypy.config.update({'server.socket_host': '192.168.1.123'})
As long as you're on the same network, you should be able to access the application on that IP/port that you set: http://192.168.1.123:8080/ (or similar)
If you need to change IP and port, use this:
cherrypy.config.update({
'server.socket_host' : '127.0.0.1',
'server.socket_port' : 9090,
})