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)) s.setServiceParent(application) ===========================
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 k callbackKeywords=kw) File "E:\Python\Lib\site-packages\twisted\internet\defer.py", line 182, in addCallbac ks self._runCallbacks() --- <exception caught here> --- File "E:\Python\Lib\site-packages\twisted\internet\defer.py", line 307, in _runCallba cks self.result = callback(self.result, *args, **kw) File "E:\Python\Lib\site-packages\twisted\web2\server.py", line 317, in _handleSegmen t 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
Best,
Jeff
Jeff Grimmett wrote:
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)
I'm fairly sure that addHost never accepted a server.Site, even in twisted.web but it most certainly doesn't in web2.
simply change the above to
== root.addHost('www.grimmlabs.com', static.File("d:sites\site1")) root.addHost('www.g-labs.com', static.File("d:sites\site2")) ==
-David
On 3/20/06, David Reid dreid@dreid.org wrote:
Jeff Grimmett wrote:
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)
I'm fairly sure that addHost never accepted a server.Site, even in
twisted.web but it most certainly doesn't in web2.
You're right, I mistyped that part. Therefore ...
simply change the above to
== root.addHost('www.grimmlabs.com', static.File("d:sites\site1")) root.addHost('www.g-labs.com', static.File("d:sites\site2")) ==
... was already that way, more or less. Sorry for the confusion.
-- "Ladies and gentlemen, there's nothing to worry about ... but please keep your heads down." - The Muppet Show
Best,
Jeff
THIS JUST IN
I'm a spaz.
I *did* accurately copy over my web2 version of the script. I don't know how I managed that, but good catch. I've put things to the way they should be and am now up and running.
Thanks for pointing out the obvious. Sometimes I need it :)
On 3/20/06, Jeff Grimmett grimmtooth@gmail.com wrote:
On 3/20/06, David Reid dreid@dreid.org wrote:
Jeff Grimmett wrote:
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)
I'm fairly sure that addHost never accepted a server.Site, even in
twisted.web but it most certainly doesn't in web2.
You're right, I mistyped that part. Therefore ...
simply change the above to
== root.addHost('www.grimmlabs.com', static.File("d:sites\site1")) root.addHost('www.g-labs.com', static.File ("d:sites\site2")) ==
... was already that way, more or less. Sorry for the confusion.
-- "Ladies and gentlemen, there's nothing to worry about ... but please keep your heads down." - The Muppet Show
Best,
Jeff
-- "Ladies and gentlemen, there's nothing to worry about ... but please keep your heads down." - The Muppet Show
Best,
Jeff