4

here i have this little example snippet and it just wont serve index.html from www dir. what is wrong with the code?

from twisted.internet import reactor
from twisted.web import static, server, script
import os

DIRECTORY = os.getcwd()+"/www"
root = static.File(DIRECTORY)
root.indexNames = [ 'index.rpy', 'index.html' ]
root.processors = { '.rpy': script.ResourceScript }
site = server.Site(root)
reactor.listenTCP(8090, site)
reactor.run()

all i get is 'No Such Resource' message. Is there any way to set up logging or something to figure this out?

marrat
  • 534
  • 1
  • 6
  • 14
  • Your index.rpy needs to include `resource = ...`. Newer versions of twisted give a more informative error message. – rob Mar 30 '12 at 16:02

2 Answers2

2

Logging can be set up by adding these lines

from twisted.python import log
import sys
log.startLogging(sys.stdout)
o11c
  • 15,265
  • 4
  • 50
  • 75
Jakob Bowyer
  • 33,878
  • 8
  • 76
  • 91
  • thanks. tho logging doesnt reveal anything that could lead to solution of problem: [HTTPChannel,0,127.0.0.1] 127.0.0.1 - - [07/Aug/2011:17:21:33 +0000] "GET / HTTP/1.1" 404 145 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0" – marrat Aug 07 '11 at 17:22
0

When I got this error, I had to add the following:

def getChild(self, name, request):
    # for some reason this is needed for the root Resource to render at all
    if name == b'':
        return self
    return super().getChild(name, request)
o11c
  • 15,265
  • 4
  • 50
  • 75