我正在关注Python 的Falcon 教程。
尝试此命令时得到的响应http localhost:8000/images
是:
HTTP/1.1 500 Internal Server Error
Content-Length: 110
Content-Type: text/plain
Date: Sat, 01 Dec 2018 15:50:26 GMT
Server: waitress
Internal Server Error
The server encountered an unexpected internal server error
(generated by waitress)
我读到它是代码中的一个问题,但我找不到它,它与教程中的完全相同,app.py
文件:
import falcon
from images import Resource
api = application = falcon.API()
images = Resource()
api.add_route('/images', images)`
images.py:
import json
import falcon
class Resource(object):
def on_get(self, req, resp):
doc = {
'images': [
{
'href': '/images/1eaf6ef1-7f2d-4ecc-a8d5-6e8adba7cc0e.png'
}
]
}
# Create a JSON representation of the resource
resp.body = json.dumps(doc, ensure_ascii=False)
# The following line can be omitted because 200 is the default
# status returned by the framework, but it is included here to
# illustrate how this may be overridden as needed.
resp.status = falcon.HTTP_200
另外,我有一个名为的空文件__init__.py
,所有文件都在同一个文件夹中,C:\look\look
.
PS 我试图添加一个 HTTP 请求暂存文件(使用 PyCharm IDE),但是没有添加那种文件的选项(在我按下Ctrl+ Shift+ Alt+之后Insert)。我在任何地方都找不到如何解决这个问题。