[Twisted-web] Adding service to virtual path

Eric Chamberlain Eric.Chamberlain at zonarsystems.com
Thu Oct 21 17:20:41 EDT 2010

That was it.  If you lived near by I'd buy you a beer.  Thank you!

On Oct 21, 2010, at 1:47 PM, Marco Giusti wrote:

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

Twisted-web mailing list
Twisted-web at twistedmatrix.com<mailto:Twisted-web at twistedmatrix.com>

Confidentiality Notice: This e-mail may contain proprietary information some of which may be legally privileged. It is for the intended recipient(s) only. If you believe that it has been sent to you in error, please notify the sender by reply e-mail and delete the message. Any disclosure, copying, distribution or use of this information by someone other than the intended recipient(s) is prohibited and may be unlawful.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20101021/50dec48d/attachment.htm 

More information about the Twisted-web mailing list