我有一个Twisted Web应用程序。我想调用一个Html文件来获取GET请求。(我的Html文件位于我的Twisted应用运行的同一个文件夹中)
class Root(resource.Resource):
isLeaf = False
def render_GET(self, request):
return self.returnResponse(request)
def returnResponse(self, request):
request.setHeader(b"content-type", b"text/html")
return File("Info.html")
site = Root()
site.putChild('cache', NetworkCacheManager())
endpoints.serverFromString(reactor, "tcp:port=8080:interface=0.0.0.0").listen(server.Site(site))
reactor.run()
当我运行服务器时,我得到500错误;
Request did not return bytes
Request:
<Request at 0x10b042b48 method=GET uri=/ clientproto=HTTP/1.1>
Resource:
<__main__.Root instance at 0x10b0302d8>
Value:
FilePath('/Users/ratha/projects/TestPython/com/lob/Info.html')
这里有什么问题?
答案 0 :(得分:0)
我修好了;
def returnResponse(self, request):
f = open('Info.html', 'r')
request.setHeader(b"content-type", b"text/html")
return f.read()