2017-10-10 23 views
1

트위스티드 웹 응용 프로그램이 있습니다. 나는 GET 요청에 대한 HTML 파일을 호출 할 내가 서버를 실행하면, 임 500 오류가꼬인 html 파일 목록에서 "요청이 바이트를 반환하지 않았습니다"오류가 발생했습니다.

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() 

(내 HTML 파일 내 트위스트 응용 프로그램이 실행되는 동일한 폴더에 있습니다).;

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

다음과 같이 고정되었습니다.

def returnResponse(self, request): 
    f = open('Info.html', 'r') 
    request.setHeader(b"content-type", b"text/html") 
    return f.read()