[Twisted-web] Adding service to virtual path

Marco Giusti marco.giusti at gmail.com
Thu Oct 21 16:47:33 EDT 2010

On Thu, Oct 21, 2010 at 01:17:36PM -0700, Eric Chamberlain wrote:
> I'm trying to add a single service to a virtual path like http://localhost:8080/geospatial/geocoder/XMLRPC.
> Version info:
> Twisted: 9.0
> Python: 2.6
> The following code does not work:
> root = resource.Resource()
> srv = XMLRPCGeocoder()
> root.putChild("geospatial/geocoder/XMLRPC", srv)
> When I attempt to access the service, twisted gives the following error:
> Request failed: <ProtocolError for
> localhost:8080/geospatial/geocoder/XMLRPC: 404 Not Found>

You should put a resource for each component of the url:

	root = resource.Resource()
	geospatial = resource.Resource()
	root.putChild('geospatial', geospatial)
	geocoder = resource.Resource()
	geospatial.putChild('geocoder', geocoder)
	xmlrpc = XMLRPCGeocoder()
	geocoder.putChild('XMLRPC', xmlrpc)

I didn't double checked, but I am pretty sure that this will works.

> Looking at twisted.web.resource.Resource's source code, all it does is
> add the path to a hash array and returns nothing...

Yes, putChild does this, but this is not how path traversal works. The
path is splitted in segments which are harvested one after the other
until a resource is returned. 


Dalle virtù che si esigono in un domestico, l'Eccellenza Vostra conosce molti
padroni degni d'esser servitori?
		-- Pierre Augustin Caron de Beaumarchais

More information about the Twisted-web mailing list