我想在另一台计算机上访问我的CherryPy站点,但是我尝试过here和here的答案,但两者都没有工作。我使用的是带有的MacforPython3.5.2,我相信这是CherryPy的最新版本。这是我目前的代码,我不在乎地址是什么,只是它能工作。谢谢你的帮助!
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())编辑:
我可以从localhost:8080 127.0.0.1和0.0.0.0访问这个网站。控制台输出如下:
[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我使用空闲运行我的文件,而不是使用防火墙。
发布于 2016-08-17 14:51:14
在下面的问题评论中提到了解决方案,所以这个答案只是为了标记这个问题的答案。
解决方案:如果您想从另一台计算机上查看cherrypy应用程序,请在运行cherrypy的计算机上找到一个IP地址,使用Unix/Linux上的ifconfig或Windows上的ipconfig。然后将此IP地址设置为cherrypy配置,而不是127.0.0.1或0.0.0.0。
cherrypy.config.update({'server.socket_host': '192.168.1.123'})只要您在同一个网络上,您就应该能够访问您设置的IP/端口上的应用程序:http://192.168.1.123:8080/ (或类似的)
如果需要更改IP和端口,请使用以下命令:
cherrypy.config.update({
'server.socket_host' : '127.0.0.1',
'server.socket_port' : 9090,
})https://stackoverflow.com/questions/38558201
复制相似问题