我有一个小小的猎鹰应用程序:
import falcon
class ThingsResource:
def on_get(self, req, resq) :
#"""Handels GET requests"""
resp.status = falcon.HTTP_200
resp.body = '{"message":"hello"}'
app = falcon.API()
things = ThingsResource()
app.add_route('/things', things)我试着用这种方式运行它:
arif@ubuntu:~/dialer_api$ gunicorn things:app但是当我尝试将它与httpie连接时,我会得到这样的结果:
arif@ubuntu:~$ http localhost:8000/things
HTTP/1.1 500 Internal Server Error
Connection: close
Content-Length: 141
Content-Type: text/html
<html>
<head>
<title>Internal Server Error</title>
</head>
<body>
<h1><p>Internal Server Error</p></h1>
</body>
</html>这太琐碎了,我不知道出了什么问题?
发布于 2014-07-10 03:43:17
你的第七行,在不应该的时候缩进了。您的第6行指的是resq,而不是稍后使用的resp。这意味着后面提到resp失败的行。
每当出现这样的内部服务器错误时,通常都是因为错误的代码。你的过程应该是吐出错误的。我已经附上了您的代码的修正版本,包括确保它符合python的约定(例如,每个缩进4个空格)。像联机python代码检查器这样的工具可以帮助您处理这样的代码片段,特别是间距问题。
import falcon
class ThingsResource():
def on_get(self, req, resp):
resp.status = falcon.HTTP_200
resp.body = '{"message":"hello"}'
app = falcon.API()
things = ThingsResource()
app.add_route('/things', things)将此代码保存到另一个文件中,然后运行diff来查看我所做的更改。主要问题是研究结果和不适当的缩进。
https://stackoverflow.com/questions/24425550
复制相似问题