localhost - CherryPy Hello World 错误

标签 localhost port cherrypy

当我运行 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/

相关文章:

linux - Ampps 窗口变灰,Ubuntu 18.04 LTS

c - 如何检索所有 TCP UDP 打开端口?

c# - C# 应用程序的最大开放端口数

python - 在 Python 中禁用 TLS 重新协商

node.js - MongoDB 卡在 clientcursormon 上(等待端口 27017 上的连接)

php - 如何在本地主机和 Web 服务器上实现绝对 URL?

php - 通过互联网IP地址从一台计算机访问xampp到另一台计算机

port - 你为什么说 "TCP port"?

python - 当 Python.py 停止工作时重新启动它

python - 如何从 CherryPy 中的 GET 请求中读取参数?