gpt4 book ai didi

Python 3 (CherryPy) 服务器无法在其他计算机上运行

转载 作者:行者123 更新时间:2023-12-01 03:48:31 24 4
gpt4 key购买 nike

我想在另一台计算机上访问我的 CherryPy 网站,但我已尝试使用 here 形式的答案和 here ,但两者都不起作用。我使用的是装有 OSX El Capitan、Python 3.5.2 的 Mac,而且我相信是最新版本的 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.10.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

我使用 IDLE 运行我的文件,并且没有使用防火墙。

最佳答案

问题下方的评论中提到了解决方案,因此此答案仅用于将此问题标记为已回答。

解决方案:如果您想从另一台计算机查看cherrypy应用程序,请在Unix/Linux上使用ifconfigipconfig找到运行cherrypy的计算机上的IP地址> 在 Windows 上。然后将此 IP 地址设置为您的cherrypy 配置,而不是 127.0.0.10.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,
})

关于Python 3 (CherryPy) 服务器无法在其他计算机上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38558201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com