当我运行 CherryPy Hello World 时:
import cherrypy
class HelloWorld:
def index(self):
return "Hello world!"
index.exposed = True
cherrypy.config.update({'server.socket_port': 8080,})
cherrypy.quickstart(HelloWorld())
...我明白了:IOError:端口 8080 未绑定(bind)在“本地主机”上。会是什么呢?
最佳答案
我想当我开始使用 CherryPy 时遇到了类似的问题......但我不记得它到底是什么......但修复涉及使用配置文件而不是手动传递配置:
MyProj.conf:
[global] server.socket_host = "127.0.0.1" server.socket_port = 8080 server.thread_pool = 10
MyProj.py
import os
import cherrypy
class HelloWorld:
def index(self):
return "Hello world!"
index.exposed = True
# Assumes the config file is in the directory as the source.
conf_path = os.path.dirname(os.path.abspath(__file__))
conf_path = os.path.join(conf_path, "MyProj.conf")
cherrypy.config.update(conf_path)
cherrypy.quickstart(HelloWorld())
这肯定在这里有效。
我正在使用 Python 2.6.1 和 CherryPy 3.1.1,并使用
-W ignore
运行脚本:c:\My_path> python -W 忽略 MyProj.py
如果你在 *nix 下,你应该把
-W ignore
在 #!
在文件顶部发表评论。
关于localhost - CherryPy Hello World 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/767575/