我刚刚在我的 Windows 7 机器上安装了 python 3.2.1(32 位)和 cherrypy 3.2.1(CherryPy-3.2.1.win32-py3.exe)并尝试了 hello world 示例(通过PyScripter),但它在引擎总线启动消息后挂起。
如果我尝试通过 python.exe 启动它,我会得到以下日志:
C:\Program Files (x86)\Python32>python hello.py
[24/Jul/2011:16:24:03] ENGINE Listening for SIGTERM.
[24/Jul/2011:16:24:03] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.
[24/Jul/2011:16:24:03] ENGINE Started monitor thread 'Autoreloader'.
[24/Jul/2011:16:24:03] ENGINE Started monitor thread '_TimeoutMonitor'.
[24/Jul/2011:16:24:03] ENGINE Serving on 127.0.0.1:8080
[24/Jul/2011:16:24:03] ENGINE Bus STARTED
Exception in thread CP Server Thread-4:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 693, in read_request_headers
read_headers(self.rfile, self.inheaders)
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 202, in read_headers
raise ValueError("Illegal end of headers.")
ValueError: Illegal end of headers.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 1024, in communicate
req.parse_request()
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 578, in parse_request
success = self.read_request_headers()
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 696, in read_request_headers
self.simple_response("400 Bad Request", ex.args[0])
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 840, in simple_response
status = str(status)
TypeError: 'tuple' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python32\lib\threading.py", line 736, in _bootstr
ap_inner
self.run()
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 1174, in run
conn.communicate()
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 1080, in communicate
req.simple_response("500 Internal Server Error", format_exc())
File "C:\Program Files (x86)\Python32\lib\site-packages\cherrypy\wsgiserver\ws
giserver3.py", line 840, in simple_response
status = str(status)
TypeError: 'tuple' object is not callable
我错过了什么?
代码:
import cherrypy
class HelloWorld:
def index(self):
return "Hello world"
index.exposed = True
cherrypy.quickstart(HelloWorld())
编辑:奖金信息:我尝试了各种方法来补救这种情况,但没有结果。安装 64 位版本的 python 没有帮助,因为 cherrypy 不支持 64 位(除非我弄错了)。我试过重新安装 python 和 cherrypy 包,我试过停用所有其他可能阻止它的东西 (IIS)。一切都无济于事:-(
EDIT2:第二个好处 - 如果我用 python 2.7.2 安装它一切正常,所以似乎它只是 3.x 的问题(我也试过 3.0.1 - 同样的问题)
最佳答案
我遇到了两个错误:
1 - 在启动脚本之前打开您的浏览器,这样您就不会遇到任何问题。
2 - 如果您使用个人防火墙或处理 HTTP 保护的防病毒软件,请确保他没有保护 8080 端口,例如 ESET Antivirus 不会让您使用 8080,CherryPy 会说该端口不可用.
关于python-3.x - Hello World 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6807428/