[Twisted-web] NameVirtualHost and web2

Jeff Grimmett grimmtooth at gmail.com
Mon Mar 20 00:25:04 CST 2006

I've a working NameVirtualHost setup that I am trying to convert over to
web2 and I've hit a speedbump. Here's the code, more or less:

from twisted.web2 import server, http, channel, vhost
from twisted.web2 import static

root = vhost.NameVirtualHost()

site1 = server.Site(static.File("d:sites\site1"))
site2 = server.Site(static.File("d:sites\site2"))

root.addHost('www.grimmlabs.com', site1)
root.addHost('www.g-labs.com', site2)

site = server.Site(root)

# Standard twisted application Boilerplate
from twisted.application    import strports, service
from twisted.internet       import reactor

application = service.Application("Grimmlabs")
s = strports.service('tcp:8080', channel.HTTPFactory(site))

Run using twistd -ny file.py

Starts up, no probs. When I go to load a page, though, I see this traceback:

          File "E:\Python\Lib\site-packages\twisted\web2\server.py", line
263, in process
            d = self._getChild(self.site.resource, self.postpath)
          File "E:\Python\Lib\site-packages\twisted\web2\server.py", line
290, in _getChild
            return defer.maybeDeferred(
          File "E:\Python\Lib\site-packages\twisted\internet\defer.py", line
191, in addCallbac
          File "E:\Python\Lib\site-packages\twisted\internet\defer.py", line
182, in addCallbac
        --- <exception caught here> ---
          File "E:\Python\Lib\site-packages\twisted\internet\defer.py", line
307, in _runCallba
            self.result = callback(self.result, *args, **kw)
          File "E:\Python\Lib\site-packages\twisted\web2\server.py", line
317, in _handleSegmen
            newres = iweb.IResource(newres)
          File "E:\Python\lib\site-packages\zope\interface\interface.py",
line 703, in __call__

            raise TypeError("Could not adapt", obj, self)
        exceptions.TypeError: ('Could not adapt',
<twisted.web2.server.Siteobject at 0x00D9157
0>, <SpecialAdaptInterfaceClass twisted.web2.iweb.IResource>)

(sorry about the formatting)

I've tried a few variations with more or less the same results. Note that
the sites I am trying to add all work just fine in web2 without the
NameVirtualHost in the mix.

I've looked over the examples and what docs we have here, and haven't come
up with any inspiration. Help me Obi-wan Kenobi, you're my only hope...

"Ladies and gentlemen, there's nothing to worry about ... but please keep
your heads down." - The Muppet Show


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20060320/39afe2d4/attachment.htm

More information about the Twisted-web mailing list